#define _GNU_SOURCE
#include <pthread.h>
#include <signal.h>
-#include <semaphore.h>
#ifdef HAVE_GETTID
#include <sys/types.h>
mutex_t *mutex;
/**
- * Semaphore used to sync the creation/start of the thread.
- */
- sem_t created;
-
- /**
* TRUE if this thread has been detached or joined, i.e. can be cleaned
* up after terminating.
*/
this->cleanup_handlers->destroy(this->cleanup_handlers);
this->mutex->unlock(this->mutex);
this->mutex->destroy(this->mutex);
- sem_destroy(&this->created);
free(this);
}
.cleanup_handlers = linked_list_create(),
.mutex = mutex_create(MUTEX_TYPE_DEFAULT),
);
- sem_init(&this->created, FALSE, 0);
return this;
}
{
void *res;
- sem_wait(&this->created);
current_thread->set(current_thread, this);
pthread_cleanup_push((thread_cleanup_t)thread_cleanup, this);
this->main = main;
this->arg = arg;
+ id_mutex->lock(id_mutex);
+ this->id = next_id++;
+ id_mutex->unlock(id_mutex);
+
if (pthread_create(&this->thread_id, NULL, (void*)thread_main, this) != 0)
{
DBG1(DBG_LIB, "failed to create thread!");
thread_destroy(this);
return NULL;
}
- id_mutex->lock(id_mutex);
- this->id = next_id++;
- id_mutex->unlock(id_mutex);
- sem_post(&this->created);
return &this->public;
}