A colleague is debugging thread issues in
a program that uses Tcl's collection of
thread-related routines as a cross-platform
threading library. When using the Google
tool "ThreadSanitizer" to examine the program
http://code.google.com/p/data-race-test/wiki/ThreadSanitizer
a report comes back claiming that the double check
locking scheme in Tcl_MutexLock is susceptible to a
race condition. Some links on the subject:
http://www.aristeia.com/Papers/DDJ_Jul_Aug_2004_revised.pdf
http://bartoszmilewski.wordpress.com/2008/11/05/who-ordered-memory-fences-on-an-x86/
The output from ThreadSanitizer:
==6800== INFO: T2 has been created by T0. Use --announce-threads to see the creation stack.
==6800== INFO: T3 has been created by T0. Use --announce-threads to see the creation stack.
==6800== WARNING: Possible data race during read of size 8 at 0x7FFEFF1D68: {{{
==6800== T3 (L{}):
==6800== #0 Tcl_MutexLock /local/home/donahue/ftp/tmp/tcl8.5.8/unix/../unix/tclUnixThrd.c:519
==6800== #1 Oxs_Mutex::Lock() /local/home/donahue/nobackup/tmp/valgrind/oommf/app/oxs/base/oxsthread.h:76
==6800== #2 Oxs_ThreadControl::Lock() /local/home/donahue/nobackup/tmp/valgrind/oommf/app/oxs/base/oxsthread.h:166
==6800== #3 _Oxs_ThreadBush_main(void*) /local/home/donahue/nobackup/tmp/valgrind/oommf/app/oxs/base/oxsthread.cc:652
==6800== #4 NewThreadProc /local/home/donahue/ftp/tmp/tcl8.5.8/unix/../generic/tclEvent.c:1487
==6800== #5 ThreadSanitizerStartThread /b/slave/full_linux_build/build/tsan/ts_valgrind_intercepts.c:609
==6800== Concurrent write(s) happened at (OR AFTER) these points:
==6800== T2 (L{L3}):
==6800== #0 Tcl_MutexLock /local/home/donahue/ftp/tmp/tcl8.5.8/unix/../unix/tclUnixThrd.c:528
==6800== #1 Oxs_Mutex::Lock() /local/home/donahue/nobackup/tmp/valgrind/oommf/app/oxs/base/oxsthread.h:76
==6800== #2 Oxs_ThreadControl::Lock() /local/home/donahue/nobackup/tmp/valgrind/oommf/app/oxs/base/oxsthread.h:166
==6800== #3 _Oxs_ThreadBush_main(void*) /local/home/donahue/nobackup/tmp/valgrind/oommf/app/oxs/base/oxsthread.cc:652
==6800== #4 NewThreadProc /local/home/donahue/ftp/tmp/tcl8.5.8/unix/../generic/tclEvent.c:1487
==6800== #5 ThreadSanitizerStartThread /b/slave/full_linux_build/build/tsan/ts_valgrind_intercepts.c:609
==6800== Location 0x7FFEFF1D68 is 62096 bytes inside T0's stack [0x7FFE000FF8,0x7FFF000FF8]
==6800== Locks involved in this report (reporting last lock sites): {L3}
==6800== L3 (0x5334900)
==6800== #0 pthread_mutex_lock /b/slave/full_linux_build/build/tsan/ts_valgrind_intercepts.c:850
==6800== #1 Tcl_MutexLock /local/home/donahue/ftp/tmp/tcl8.5.8/unix/../unix/tclUnixThrd.c:520
==6800== #2 Oxs_Mutex::Lock() /local/home/donahue/nobackup/tmp/valgrind/oommf/app/oxs/base/oxsthread.h:76
==6800== #3 Oxs_ThreadControl::Lock() /local/home/donahue/nobackup/tmp/valgrind/oommf/app/oxs/base/oxsthread.h:166
==6800== #4 _Oxs_ThreadBush_main(void*) /local/home/donahue/nobackup/tmp/valgrind/oommf/app/oxs/base/oxsthread.cc:652
==6800== #5 NewThreadProc /local/home/donahue/ftp/tmp/tcl8.5.8/unix/../generic/tclEvent.c:1487
==6800== #6 ThreadSanitizerStartThread /b/slave/full_linux_build/build/tsan/ts_valgrind_intercepts.c:609
==6800== Race verifier data: 0x50F364A,0x50F3692
==6800== }}}
I have a vague sense that this is a known issue already,
and the threading gurus in the Tcl world have some reason
to believe it's not a real problem. Perhaps the only new
issue here is the existence of a tool that will point a
finger of blame at us, and whether there's anyhting that
can or should be done about that.
|