On Thu, Jul 02, 2009 at 08:53:21AM -0500, David Fries wrote:
> Here is a fix for a deadlock seen under Windows using OpenThreads
> Barrier operations.  The error is with atomic operations in the
> win32 condition implementation.  The attached sample program will
> reliably trigger with as few as three threads and a dual core system,
> though sometimes it will take 65,000 iterations.

Oops, I included the full file, but forgot the patch.

Index: src/OpenThreads/win32/Win32ConditionPrivateData.h
===================================================================
--- src/OpenThreads/win32/Win32ConditionPrivateData.h   (revision 10273)
+++ src/OpenThreads/win32/Win32ConditionPrivateData.h   (working copy)
@@ -68,7 +68,7 @@
         if (have_waiters)
         {
             // Wake up all the waiters.
-            ReleaseSemaphore(sema_.get(),waiters_,NULL);
+            ReleaseSemaphore(sema_.get(), w, NULL);
 
             cooperativeWait(waiters_done_.get(), INFINITE);
 
@@ -112,8 +112,7 @@
         }
         catch(...){
             // thread is canceled in cooperative wait , do cleanup
-            InterlockedDecrement(&waiters_);
-            long w = InterlockedGet(&waiters_);
+            long w = InterlockedDecrement(&waiters_);
             int last_waiter = was_broadcast_ && w == 0;
 
             if (last_waiter)  SetEvent(waiters_done_.get());
@@ -123,8 +122,7 @@
 
         
         // We're ready to return, so there's one less waiter.
-        InterlockedDecrement(&waiters_);
-        long w = InterlockedGet(&waiters_);
+        long w = InterlockedDecrement(&waiters_);
         int last_waiter = was_broadcast_ && w == 0;
 
         if (result != -1 && last_waiter)


-- 
David Fries <[email protected]>
http://fries.net/~david/ (PGP encryption key available)
_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to