[Patch] Fix gethwnd race

Christopher Faylor cgf-no-personal-reply-please@cygwin.com
Thu May 13 21:03:00 GMT 2004

On Thu, May 13, 2004 at 03:28:12PM -0500, Brian Ford wrote:
>On Thu, 13 May 2004, Christopher Faylor wrote:
>> >I can't seem to make a muto fit this situation cleanly since it would
>> >have to be acquired and released by the same thread.
>> Why would it be acquired and released from the same thread?
>What I was trying to say is that a muto must be acquired and released from
>the same thread.  But here, we want to block all threads calling gethwnd
>until the window thread has initialized.
>> Isn't the problem that multiple people are calling gethwnd?
>Concurrently, before ourhwnd has been initialized, yes.
>> You even mention this in the ChangeLog below.  Given that, the place to
>> put a mutex would seem to be in gethwnd.
>It seems to me that you would still need the window_started event then,
>no?  Since a muto contains an event, why use two?  I thought this was
>lighter weight.

Either the hwnd exists or it doesn't.

If it does exist, just return it.  No locking required.

If it doesn't exist, acquire the muto.  Does the hwnd exist now?
If so, release the muto and return the hwnd.

Otherwise, set up hwnd, release the muto and return hwnd.


More information about the Cygwin-patches mailing list