{"id":35433,"date":"2005-06-06T08:57:34","date_gmt":"2005-06-06T08:57:34","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2005\/06\/06\/a-quick-puzzle-about-security-and-synchronization\/"},"modified":"2005-06-06T08:57:34","modified_gmt":"2005-06-06T08:57:34","slug":"a-quick-puzzle-about-security-and-synchronization","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20050606-34\/?p=35433","title":{"rendered":"A quick puzzle about security and synchronization"},"content":{"rendered":"<p>\nThis quick puzzle floated past one of our internal discussion groups.\n<\/p>\n<pre>\n\/\/ in process A\nhEventA = CreateEvent(NULL, FALSE, TRUE, TEXT(\"MyNamedEvent\"));\n\/\/ in process B\nhEventB = OpenEvent(EVENT_MODIFY_STATE, FALSE, TEXT(\"MyNamedEvent\"));\nWaitForSingleObject(hEventB, INFINITE);\n<\/pre>\n<p>\nIn Process&nbsp;B, the <code>OpenEvent<\/code> succeeds, but the\n<code>WaitForSingleObject<\/code> returns immediately instead of\nwaiting.  Explain.\n<\/p>\n<p>\n[Correction: I confused the matter by passing <code>TRUE<\/code> as\nthe third parameter, thereby creating an event that is initially\nsignalled.  Change it to <code>FALSE<\/code> so that the event\nis created non-signalled, in which case the\n<code>WaitForSingleObject<\/code> would be expected to wait.]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This quick puzzle floated past one of our internal discussion groups. \/\/ in process A hEventA = CreateEvent(NULL, FALSE, TRUE, TEXT(&#8220;MyNamedEvent&#8221;)); \/\/ in process B hEventB = OpenEvent(EVENT_MODIFY_STATE, FALSE, TEXT(&#8220;MyNamedEvent&#8221;)); WaitForSingleObject(hEventB, INFINITE); In Process&nbsp;B, the OpenEvent succeeds, but the WaitForSingleObject returns immediately instead of waiting. Explain. [Correction: I confused the matter by passing TRUE as [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-35433","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>This quick puzzle floated past one of our internal discussion groups. \/\/ in process A hEventA = CreateEvent(NULL, FALSE, TRUE, TEXT(&#8220;MyNamedEvent&#8221;)); \/\/ in process B hEventB = OpenEvent(EVENT_MODIFY_STATE, FALSE, TEXT(&#8220;MyNamedEvent&#8221;)); WaitForSingleObject(hEventB, INFINITE); In Process&nbsp;B, the OpenEvent succeeds, but the WaitForSingleObject returns immediately instead of waiting. Explain. [Correction: I confused the matter by passing TRUE as [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35433","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=35433"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/35433\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=35433"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=35433"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=35433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}