|
From: Matthieu C. <mat...@pa...> - 2007-12-05 10:33:39
|
Hi,
it seems helgrind don't detect the lock taken by flockfile [1] and report
owner data race.
$ cat thread_fwrite_2.c
#include <pthread.h>
#include <stdio.h>
#include <stdarg.h>
#define THREAD_NUM 4
void*start(void*data)
{
flockfile(stderr);
funlockfile(stderr);
}
int main()
{
void* ret;
pthread_t tid[THREAD_NUM];
int i;
flockfile(stderr);
funlockfile(stderr);
for (i=0; i < THREAD_NUM; i++)
pthread_create(&tid[i], NULL, start, &tid[i]);
for (i=0; i < THREAD_NUM; i++)
pthread_join(tid[i], &ret);
}
$ gcc thread_fwrite_2.c -o thread_fwrite_2 -lpthread -g -O0
$ valgrind --tool=helgrind ./thread_fwrite_2
==25452== Helgrind, a thread error detector.
==25452== Copyright (C) 2007-2007, and GNU GPL'd, by OpenWorks LLP et al.
==25452== Using LibVEX rev 1800, a library for dynamic binary translation.
==25452== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==25452== Using valgrind-3.3.0.SVN, a dynamic binary instrumentation framework.
==25452== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==25452== For more details, rerun with: -v
==25452==
==25452== Thread #2 was created
==25452== at 0x412A5F8: clone (in /lib/i686/cmov/libc-2.7.so)
==25452== by 0x4027625: pthread_create@* (hg_intercepts.c:213)
==25452== by 0x804854D: main (thread_fwrite_2.c:22)
==25452==
==25452== Thread #3 was created
==25452== at 0x412A5F8: clone (in /lib/i686/cmov/libc-2.7.so)
==25452== by 0x4027625: pthread_create@* (hg_intercepts.c:213)
==25452== by 0x804854D: main (thread_fwrite_2.c:22)
==25452==
==25452== Possible data race during write of size 4 at 0x419E0E4
==25452== at 0x4049DBF: flockfile (in /lib/i686/cmov/libpthread-2.7.so)
==25452== by 0x80484D6: start (thread_fwrite_2.c:9)
==25452== by 0x4027710: mythread_wrapper (hg_intercepts.c:193)
==25452== by 0x40414FA: start_thread (in /lib/i686/cmov/libpthread-2.7.so)
==25452== by 0x412A60D: clone (in /lib/i686/cmov/libc-2.7.so)
==25452== Old state: shared-readonly by threads #2, #3
==25452== New state: shared-modified by threads #2, #3
==25452== Reason: this thread, #3, holds no consistent locks
==25452== Location 0x419E0E4 has never been protected by any lock
==25452==
==25452== Possible data race during write of size 4 at 0x419E0E0
==25452== at 0x4049DC2: flockfile (in /lib/i686/cmov/libpthread-2.7.so)
==25452== by 0x80484D6: start (thread_fwrite_2.c:9)
==25452== by 0x4027710: mythread_wrapper (hg_intercepts.c:193)
==25452== by 0x40414FA: start_thread (in /lib/i686/cmov/libpthread-2.7.so)
==25452== by 0x412A60D: clone (in /lib/i686/cmov/libc-2.7.so)
==25452== Old state: shared-readonly by threads #2, #3
==25452== New state: shared-modified by threads #2, #3
==25452== Reason: this thread, #3, holds no consistent locks
==25452== Location 0x419E0E0 has never been protected by any lock
==25452==
==25452== ERROR SUMMARY: 2 errors from 2 contexts
(suppressed: 2 from 1)
[1]
nptl/sysdeps/pthread/bits/stdio-lock.h
#define _IO_lock_lock(_name) \
do { \
void *__self = THREAD_SELF; \
if ((_name).owner != __self) \
{ \
lll_lock ((_name).lock, LLL_PRIVATE); \
(_name).owner = __self; \
} \
++(_name).cnt; \
} while (0)
|