Skip to content
Snippets Groups Projects
Commit ee7273b6 authored by Aidan Chalk's avatar Aidan Chalk
Browse files

Fixed a bug with pthread IDs and made the scheduler threadsafe using our gnu99...

Fixed a bug with pthread IDs and made the scheduler threadsafe using our gnu99 not really safe method #13
parent ea3779e7
No related branches found
No related tags found
1 merge request!8[WIP] Fortran bindings
......@@ -52,6 +52,8 @@ char *qsched_timer_names[ qsched_timer_count ] =
#if defined( HAVE_PTHREAD )
pthread_key_t qsched_pointer;
volatile int key_exists = 0;
volatile int pthread_key_mutex;
#endif
/**
......@@ -536,7 +538,7 @@ void qsched_run ( struct qsched *s , int nr_threads , qsched_funtype fun ) {
int qsched_get_tid() {
struct qsched *s = NULL;
#if defined( HAVE_PTHREAD )
s = (struct qsched *)pthread_getspecific(qsched_pointer);
s = (struct qsched *)pthread_getspecific(qsched_pointer);
#endif
if( s != NULL )
return *(int*)pthread_getspecific(s->thread_id_key);
......@@ -1655,7 +1657,12 @@ void qsched_init ( struct qsched *s , int nr_queues , int flags ) {
error( "Failed to lock barrier mutex." );
}
pthread_key_create(&s->thread_id_key, NULL);
pthread_key_create(&qsched_pointer, NULL);
while(__sync_val_compare_and_swap(&pthread_key_mutex, 0, 1)!=0);
if(!key_exists){
pthread_key_create(&qsched_pointer, NULL);
key_exists=1;
}
pthread_key_mutex = 0;
#endif
/* Clear the timers. */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment