Hi Julian, all,
I get a report about a race from helgrind, while everything looks well
synchronized to me.
Am I wrong?
Thanks,
--kcc
% cat cv.cc
#define _MULTI_THREADED
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static int COND = 0;
static pthread_cond_t CV = PTHREAD_COND_INITIALIZER;
static pthread_mutex_t MU = PTHREAD_MUTEX_INITIALIZER;
void *run_pm(void*) {
sleep(2); // we want waiter to get there first
pthread_mutex_lock(&MU);
COND++;
fprintf(stderr, "Signal: COND: %d\n", COND);
pthread_cond_signal(&CV);
pthread_mutex_unlock(&MU);
return NULL;
}
int main() {
pthread_t threadid;
pthread_create(&threadid, NULL, run_pm, NULL);
pthread_mutex_lock(&MU);
while (COND != 1) {
fprintf(stderr, "Wait: COND: %d\n", COND);
pthread_cond_wait(&CV, &MU);
}
pthread_mutex_unlock(&MU);
fprintf(stderr, "COND: %d\n", COND);
pthread_join(threadid, NULL);
return 0;
}
% g++ -g cv.cc -lpthread
% ~/race/valgrind32orig/Inst/bin/valgrind --tool=helgrind ./a.out
==31530== Helgrind, a thread error detector.
==31530== Copyright (C) 2007-2007, and GNU GPL'd, by OpenWorks LLP et al.
==31530== Using LibVEX rev 1793, a library for dynamic binary translation.
==31530== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==31530== Using valgrind-3.3.0.RC1, a dynamic binary instrumentation
framework.
==31530== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==31530== For more details, rerun with: -v
==31530==
Wait: COND: 0
Signal: COND: 1
==31530== Thread #1 is the program's root thread
==31530==
==31530== Thread #2 was created
==31530== at 0x4FF1A4D8: clone (in /lib/tls/i686/cmov/libc-2.3.6.so)
==31530== by 0x410B37E2: pthread_create@@GLIBC_2.1 (in
/lib/tls/i686/cmov/libpthread-2.3.6.so)
==31530== by 0x47A749A: [EMAIL PROTECTED] (hg_intercepts.c:213)
==31530== by 0x80486FC: main (cv.cc:23)
==31530==
==31530== Possible data race during read of size 4 at 0x8049AB8
==31530== at 0x8048754: main (cv.cc:32)
==31530== Old state: shared-modified by threads #1, #2
==31530== New state: shared-modified by threads #1, #2
==31530== Reason: this thread, #1, holds no consistent locks
==31530== Last consistently used lock for 0x8049AB8 was first observed
==31530== at 0x47A7916: pthread_mutex_lock (hg_intercepts.c:408)
==31530== by 0x8048708: main (cv.cc:25)
COND: 1
==31530==
==31530== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 16 from 4)
%
-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell. From the desktop to the data center, Linux is going
mainstream. Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers