------- Comment #70 from dominiq at lps dot ens dot fr 2010-06-03 18:23 ------- (In reply to comment #68) > That makes sense, so all we need to do in config/tls.m4 is probably: > 1) move a_in_main_thread variable to file scope, and neither a_in_main_thread > nor a_in_other_thread should be static > 2) move a_in_main_thread = &a; before pthread_create > That should be IMHO all that is needed, the compiler can't then move > a_in_main_thread assignment after pthread_create. Or to be really sure make > a_in_main_thread and a_in_other_thread volatile too.
Does this code follow these instructions? #include <pthread.h> __thread int a; int *a_in_main_thread; int *a_in_other_thread; static void * thread_func (void *arg) { a_in_other_thread = &a; return (void *)0; } int main () { pthread_t thread; void *thread_retval; a_in_main_thread = &a; if (pthread_create (&thread, (pthread_attr_t *)0, thread_func, (void *)0)) return 0; if (pthread_join (thread, &thread_retval)) return 0; return (a_in_other_thread == a_in_main_thread); ; return 0; } I have compiled it with -O2 -g -pthread and ran it 10000 times on a loaded system without failure. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43170