From: Andrzej K. Haczewski Date: Wed, 04 Nov 2009 10:53:30 GMT Subject: Re: [PATCH 1/1] MSVC: port pthread code to native Windows threads Message-ID: <16cee31f0911040253t57e9f8a4le70db2f5607fd645@mail.gmail.com> In-Reply-To: <4AF13819.7050306@viscovery.net> 2009/11/4 Johannes Sixt : > Can't you just use the pthread package that is included in msysgit? I don't like bloat, and msysgit is bloated. Sure, there are parts of msysgit that are even heavier (bash, perl), but this will be removed with further C'ification of scripts. I did what I thought could be sensible for my first patch. I'm newbie after all. >> +     /* we're waiting... */ >> +     EnterCriticalSection(&cond->waiters_lock); >> +     ++cond->waiters; >> +     LeaveCriticalSection(&cond->waiters_lock); >> + >> +     /* unlock external mutex and wait for signal */ >> +     LeaveCriticalSection(mutex); >> +     result = WaitForSingleObject(cond->sema, INFINITE); > > Releasing the mutex and entering the wait state as well as leaving the > wait state and reacquiring the mutex should be atomic. Neither are in this > implementation. You are not mentioning why you are implementing things > like this and why this would be acceptable. It's safe to do it like this here because we're serializing waiters count and when signaling we make sure we have waiters before we release semaphore. That implementation is based on ACE. Andrew