[Patch] Fix gethwnd race

Brian Ford ford@vss.fsi.com
Thu May 13 21:21:00 GMT 2004

On Thu, 13 May 2004, Christopher Faylor wrote:

> Either the hwnd exists or it doesn't.


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

Ok, add:

if (ourhwnd)
  return ourhwnd;

to the beginning of my patch if your worried about the interlocked
overhead and don't mind a double test.

> If it doesn't exist, acquire the muto.

Ok, but now you have a new persistent object including an event.

> Does the hwnd exist now?  If so, release the muto and return the hwnd.

My patch does that without the muto.

> Otherwise, set up hwnd,

by waiting on the other thread with an event?  Since you already need that
event, why not use it instead of a muto?  You can clean up the event when
your done.  The muto stays around until the process exits.

> release the muto and return hwnd.

essentially exactly the same as my patch with one more uncleanable

Yes, I thought of that but it didn't seem as clean.  Once again, I don't
care, but I did have a good reason for choosing the method I presented.
(At least, IMHO it was a good reason).

Brian Ford
Senior Realtime Software Engineer
VITAL - Visual Simulation Systems
FlightSafety International
the best safety device in any aircraft is a well-trained pilot...

More information about the Cygwin-patches mailing list