On Thu, Feb 5, 2009 at 4:26 PM, Christoph Bartoschek
<bartosc...@or.uni-bonn.de> wrote:
> today I had to learn that the attached program is incorrect. It is not allowed
> to destroy the barrier while not all threads have left the
> pthread_barrier_wait() call.
>
> Unfortunately neither DRD nor Helgrind warn about this error. Could you please
> improve the tools to detect such errors?
>
> Christoph
>
> #include <pthread.h>
> #include <stdlib.h>
>
> pthread_barrier_t * barrier;
>
> void * thread(void * arg) {
>   pthread_barrier_wait(barrier);
>   return NULL;
> }
>
> int main() {
>   pthread_t tid;
>
>   barrier = (pthread_barrier_t *) malloc(sizeof(*barrier));
>   pthread_barrier_init(barrier, NULL, 2);
>
>   pthread_create(&tid, NULL, thread, NULL);
>
>   pthread_barrier_wait(barrier);
>   pthread_barrier_destroy(barrier);
>   free(barrier);
>
>   pthread_join(tid, NULL);
>   return 0;
> }

The latest trunk revision of DRD (r9214 or later) should now always
print an error message for the above example: depending on how threads
are scheduled, DRD will either complain that a barrier is being
destroyed that is still in use or that synchronization between
pthread_barrier_wait() and pthread_barrier_destroy() was missing. The
last case can be forced by inserting sleep(1) just before the call to
pthread_barrier_destroy().

Thanks for reporting this.

Bart.

------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to