|
From: Christoph B. <bar...@or...> - 2009-02-05 17:35:16
|
Am Donnerstag, 5. Februar 2009 schrieb Julian Seward: > On Thursday 05 February 2009, Christoph Bartoschek wrote: > > Hi, > > > > 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? > > Um, where is the bug in this program? To me it looks OK: the barrier > is not destroyed until after both parent and child have passed it. > For me this also looked ok till now. But the standard seems not to guarantee that this works. I have asked about this in comp.programming.threads: http://groups.google.com/group/comp.programming.threads/browse_thread/thread/4f65535d6192aa50/a5f4bf1e3b437c4d?lnk=st&q=#a5f4bf1e3b437c4d My explanation is that the threads need still access to the barrier after being woken up from the wait. When the last thread reaches the barrier all waiting threads are woken up but they are not yet finished with pthread_barrier_wait(). When the first thread leaving pthread_barrier_wait() destroys the barrier, then the other threads cannot perform their final tasks in pthread_barrier_wait(). Christoph |