June 6th, 2005

A quick puzzle about security and synchronization

This quick puzzle floated past one of our internal discussion groups.

// in process A
hEventA = CreateEvent(NULL, FALSE, TRUE, TEXT("MyNamedEvent"));
// in process B
hEventB = OpenEvent(EVENT_MODIFY_STATE, FALSE, TEXT("MyNamedEvent"));
WaitForSingleObject(hEventB, INFINITE);

In Process B, the OpenEvent succeeds, but the WaitForSingleObject returns immediately instead of waiting. Explain.

[Correction: I confused the matter by passing TRUE as the third parameter, thereby creating an event that is initially signalled. Change it to FALSE so that the event is created non-signalled, in which case the WaitForSingleObject would be expected to wait.]

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.