> I get a report about a race from helgrind, while everything looks well
> synchronized to me.
> Am I wrong?

>   fprintf(stderr, "COND: %d\n", COND);
>   pthread_join(threadid, NULL);

The problem is here.  By the time you get here, Helgrind knows that
COND has been accessed by both parent and child threads, and MU is
used to protect it.  But now you are using it without a lock.

Helgrind cannot know that the child thread (run_pm) does not access 
COND again after the pthread_cond_signal (how could it know this
without doing static analysis of the child's code?)

If you change the order of these two lines, to

>   pthread_join(threadid, NULL);
>   fprintf(stderr, "COND: %d\n", COND);

then it stops complaining.  Because now the pthread_join tells Helgrind
that the child can no longer access COND.  That means, after the pthread_join,
the parent is the only thread able to access COND, so it is OK for it
to access COND without a lock.

J

-------------------------------------------------------------------------
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

Reply via email to