William Good
2017-05-29 17:33:42 UTC
Hello,
I am trying to understand this helgrind output. It says there is a data-race on a read. However both threads hold the same lock. How can this be a race when both threads hold the lock during the access?
==31341== ----------------------------------------------------------------
==31341==
==31341== Lock at 0x5990828 was first observed
==31341== at 0x4C31A76: pthread_mutex_init (hg_intercepts.c:779)
==31341== by 0x4026AF: thread_pool_submit (threadpool.c:85)
==31341== by 0x402012: qsort_internal_parallel (quicksort.c:142)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402450: thread_work (threadpool.c:233)
==31341== by 0x4C3083E: mythread_wrapper (hg_intercepts.c:389)
==31341== by 0x4E42DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==31341== by 0x5355CEC: clone (in /usr/lib64/libc-2.17.so)
==31341== Address 0x5990828 is 40 bytes inside a block of size 152 alloc'd
==31341== at 0x4C2CD95: calloc (vg_replace_malloc.c:711)
==31341== by 0x4026A1: thread_pool_submit (threadpool.c:84)
==31341== by 0x402012: qsort_internal_parallel (quicksort.c:142)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x40279F: future_get (threadpool.c:112)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402450: thread_work (threadpool.c:233)
==31341== by 0x4C3083E: mythread_wrapper (hg_intercepts.c:389)
==31341== by 0x4E42DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==31341== by 0x5355CEC: clone (in /usr/lib64/libc-2.17.so)
==31341== Block was alloc'd by thread #3
==31341==
==31341== Possible data race during read of size 4 at 0x5990880 by thread #2
==31341== Locks held: 1, at address 0x5990828
==31341== at 0x4023A9: thread_work (threadpool.c:229)
==31341== by 0x4C3083E: mythread_wrapper (hg_intercepts.c:389)
==31341== by 0x4E42DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==31341== by 0x5355CEC: clone (in /usr/lib64/libc-2.17.so)
==31341==
==31341== This conflicts with a previous write of size 4 by thread #3
==31341== Locks held: 1, at address 0x5990828
==31341== at 0x4027B3: future_get (threadpool.c:114)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x40279F: future_get (threadpool.c:112)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x40279F: future_get (threadpool.c:112)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== Address 0x5990880 is 128 bytes inside a block of size 152 alloc'd
==31341== at 0x4C2CD95: calloc (vg_replace_malloc.c:711)
==31341== by 0x4026A1: thread_pool_submit (threadpool.c:84)
==31341== by 0x402012: qsort_internal_parallel (quicksort.c:142)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x40279F: future_get (threadpool.c:112)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402450: thread_work (threadpool.c:233)
==31341== by 0x4C3083E: mythread_wrapper (hg_intercepts.c:389)
==31341== by 0x4E42DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==31341== by 0x5355CEC: clone (in /usr/lib64/libc-2.17.so)
==31341== Block was alloc'd by thread #3
==31341==
==31341== ----------------------------------------------------------------
I am trying to understand this helgrind output. It says there is a data-race on a read. However both threads hold the same lock. How can this be a race when both threads hold the lock during the access?
==31341== ----------------------------------------------------------------
==31341==
==31341== Lock at 0x5990828 was first observed
==31341== at 0x4C31A76: pthread_mutex_init (hg_intercepts.c:779)
==31341== by 0x4026AF: thread_pool_submit (threadpool.c:85)
==31341== by 0x402012: qsort_internal_parallel (quicksort.c:142)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402450: thread_work (threadpool.c:233)
==31341== by 0x4C3083E: mythread_wrapper (hg_intercepts.c:389)
==31341== by 0x4E42DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==31341== by 0x5355CEC: clone (in /usr/lib64/libc-2.17.so)
==31341== Address 0x5990828 is 40 bytes inside a block of size 152 alloc'd
==31341== at 0x4C2CD95: calloc (vg_replace_malloc.c:711)
==31341== by 0x4026A1: thread_pool_submit (threadpool.c:84)
==31341== by 0x402012: qsort_internal_parallel (quicksort.c:142)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x40279F: future_get (threadpool.c:112)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402450: thread_work (threadpool.c:233)
==31341== by 0x4C3083E: mythread_wrapper (hg_intercepts.c:389)
==31341== by 0x4E42DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==31341== by 0x5355CEC: clone (in /usr/lib64/libc-2.17.so)
==31341== Block was alloc'd by thread #3
==31341==
==31341== Possible data race during read of size 4 at 0x5990880 by thread #2
==31341== Locks held: 1, at address 0x5990828
==31341== at 0x4023A9: thread_work (threadpool.c:229)
==31341== by 0x4C3083E: mythread_wrapper (hg_intercepts.c:389)
==31341== by 0x4E42DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==31341== by 0x5355CEC: clone (in /usr/lib64/libc-2.17.so)
==31341==
==31341== This conflicts with a previous write of size 4 by thread #3
==31341== Locks held: 1, at address 0x5990828
==31341== at 0x4027B3: future_get (threadpool.c:114)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x40279F: future_get (threadpool.c:112)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x40279F: future_get (threadpool.c:112)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== Address 0x5990880 is 128 bytes inside a block of size 152 alloc'd
==31341== at 0x4C2CD95: calloc (vg_replace_malloc.c:711)
==31341== by 0x4026A1: thread_pool_submit (threadpool.c:84)
==31341== by 0x402012: qsort_internal_parallel (quicksort.c:142)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x40279F: future_get (threadpool.c:112)
==31341== by 0x402048: qsort_internal_parallel (quicksort.c:152)
==31341== by 0x402040: qsort_internal_parallel (quicksort.c:151)
==31341== by 0x402450: thread_work (threadpool.c:233)
==31341== by 0x4C3083E: mythread_wrapper (hg_intercepts.c:389)
==31341== by 0x4E42DC4: start_thread (in /usr/lib64/libpthread-2.17.so)
==31341== by 0x5355CEC: clone (in /usr/lib64/libc-2.17.so)
==31341== Block was alloc'd by thread #3
==31341==
==31341== ----------------------------------------------------------------