1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
CThread::CThread(void *(*function)(void *))
{
mutex = PTHREAD_MUTEX_INITIALIZER;
thread.push_back(0);
try {
if(pthread_create(&thread.back(), NULL, (void *(*)(void *))function, NULL) < 0)
// thread = SDL_CreateThread((int (*)(void *))function, NULL);
// if(thread == NULL)
throw string("thread.cpp : Can't create the thread");
}
catch(string caught) {
cerr << caught << endl;
throw;
}
}
bool CThread::lock() {
if(pthread_mutex_trylock(&mutex) != EBUSY)
return true;
return false;
}
void CThread::unlock() {
pthread_mutex_unlock(&mutex);
} |
Partager