[PATCH] Possible threads race condition in src/alarm.c
Reini Urban
rurban at x-ray.at
Wed Aug 29 20:50:12 UTC 2012
On Wed, Aug 29, 2012 at 10:29 PM, Reini Urban <rurban at x-ray.at> wrote:
> On Tue, Aug 28, 2012 at 4:34 PM, Andy Dougherty <doughera at lafayette.edu> wrote:
>> I've never really done any threads programming, so I could be quite off
>> here, but it looks to me as if there's a race condition in src/alarm.c in
>> the threads branch. Specifically, Parrot_alarm_init() creates a thread
>> that checks sleep_cond before it initializes sleep_cond. (Similar remarks
>> hold for alarm_lock.)
>>
>> Does this patch look appropriate?
>
> Yes, please apply.
I verified that it fixes the sleep deadlock, but with
the deadlock fix there come 3 more races detected by tsan.
(See http://blogs.perl.org/users/rurban/2012/08/threadsanitizer.html)
Before:
$ tsan --announce-threads ./parrot t/pmc/task.t
1..6
ok 1 - initialized
ok 2 task1 ran
ok 3 task2 ran
ok 4 sub1 ran
.. Deadlock in sleep cond_wait.
After:
...
ok 4 sub1 ran
==3511== INFO: T5 has been created by T0 at this point: {{{
==3511== #0 (no symbols) /lib/x86_64-linux-gnu/libpthread-2.13.so
==3511== #1 do_clone.constprop.3
/build/buildd/eglibc-2.13/nptl/../nptl/sysdeps/pthread/createthread.c:75
==3511== #2 pthread_create@@GLIBC_2.2.5
/build/buildd/eglibc-2.13/nptl/../nptl/sysdeps/pthread/createthread.c:256
==3511== #3 pthread_create@*
/mnt/data/build/slave/full_linux_build/build/tsan/ts_valgrind_intercepts.c:732
==3511== #4 Parrot_thread_run
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #5 Parrot_schedule_p
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #6 runops_fast_core
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #7 runops_int
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #8 runops
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #9 Parrot_pcc_invoke_from_sig_object
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #10 Parrot_ext_call
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #11 Parrot_Task_invoke
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== }}}
==3511== INFO: T0 is program's main thread
==3511== WARNING: Possible data race during write of size 8 at 0x42EEDB0: {{{
==3511== T0 (L{}):
==3511== #0 Parrot_Task_nci_send
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #1 Parrot_NativePCCMethod_invoke
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #2 runops_fast_core
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #3 runops_int
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #4 runops
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #5 Parrot_pcc_invoke_from_sig_object
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #6 Parrot_ext_call
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #7 Parrot_Task_invoke
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #8 Parrot_pcc_invoke_from_sig_object
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #9 Parrot_ext_call
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #10 Parrot_cx_outer_runloop
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #11 Parrot_cx_begin_execution
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== Concurrent read(s) happened at (OR AFTER) these points:
==3511== T5 (L{L31}):
==3511== #0 Parrot_receive_p
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #1 runops_fast_core
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #2 runops_int
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #3 runops
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #4 Parrot_pcc_invoke_from_sig_object
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #5 Parrot_ext_call
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #6 Parrot_Task_invoke
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #7 Parrot_pcc_invoke_from_sig_object
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #8 Parrot_ext_call
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #9 Parrot_thread_outer_runloop
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== Location 0x42EEDB0 is 864 bytes inside a block starting at
0x42EEA50 of size 4096 allocated by T0 from heap:
==3511== #0 calloc
/mnt/data/build/slave/full_linux_build/build/tsan/ts_valgrind_intercepts.c:444
==3511== #1 mem_sys_allocate_zeroed
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #2 pool_allocate
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #3 gc_gms_allocate_pmc_attributes
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #4 get_new_pmc_header
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #5 Parrot_pmc_create_mro
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #6 Parrot_Task_class_init
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #7 Parrot_gbl_initialize_core_pmcs
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #8 init_world
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #9 Parrot_interp_initialize_interpreter
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== Locks involved in this report (reporting last lock sites): {L31}
==3511== L31 (0x42EEDB8)
==3511== #0 pthread_mutex_lock
/mnt/data/build/slave/full_linux_build/build/tsan/ts_valgrind_intercepts.c:935
==3511== #1 Parrot_receive_p
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #2 runops_fast_core
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #3 runops_int
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #4 runops
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #5 Parrot_pcc_invoke_from_sig_object
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #6 Parrot_ext_call
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #7 Parrot_Task_invoke
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #8 Parrot_pcc_invoke_from_sig_object
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #9 Parrot_ext_call
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== #10 Parrot_thread_outer_runloop
/home/rurban/Perl/src/parrot/threads/blib/lib/libparrot.so.4.7.0
==3511== Race verifier data: 0x4FB11C8,0x4EAA913
==3511== }}}
and 2 more. See attachment.
--
Reini Urban
http://cpanel.net/ http://www.perl-compiler.org/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: task.log
Type: application/octet-stream
Size: 14062 bytes
Desc: not available
URL: <http://lists.parrot.org/pipermail/parrot-dev/attachments/20120829/3f1c0d3e/attachment-0001.obj>
More information about the parrot-dev
mailing list