<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic WaitForSingleObject in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/WaitForSingleObject/m-p/964389#M22510</link>
    <description>I am writing a mufti-thread program and try coordinate the execution of the main process and a  thread using the CreateEvent, SetEvent and WaitForSingleObject Win32 routines. Both, the main process and the thread, set their own event, when they are ready to receive data from the other. The thread, created by the main process should wait indefinetily.   &lt;BR /&gt;To achieve this I try to use the   &lt;BR /&gt;  &lt;BR /&gt;WaitForSingleObjecth(Event, WAIT_INFINITE)  &lt;BR /&gt;  &lt;BR /&gt;According to the CVF Programmer`I Guide I should use the DFMT and DFWIN modules, but it causes several compiler errors, as the same  routines (CREATETHREAD, WAITFORSINGLEOBJECT, etc) are declared in both. I decided to use the DFWIN routine and declare the WAIT_INFINITE integer parameter (=-1).  &lt;BR /&gt;  &lt;BR /&gt;Inteerestingly, the WAITFORSINGLEOBJECT routine in the thread returns only at evry second time, when the object (hEvent) has been signaled in the main process. Using the Debugger, setting breaks at the  &lt;BR /&gt;   &lt;BR /&gt;SETEVENT(hEvent)  &lt;BR /&gt;  &lt;BR /&gt;and the  &lt;BR /&gt;  &lt;BR /&gt;WaitForSingleObjecth(hEvent, WAIT_INFINITE)  &lt;BR /&gt;  &lt;BR /&gt;result returns for every single event. Setting breaks only one of the above, result "abnormal" return. It seems to me there might be some timing problem?  &lt;BR /&gt;  &lt;BR /&gt;To overcome the above problem the thread waits only for a definite time and if it times out, the WaitForSingleObject routine is called again and again in an infinite loop untill the hEvent object is signaled by the main process.</description>
    <pubDate>Fri, 24 Aug 2001 04:11:27 GMT</pubDate>
    <dc:creator>tkibedi</dc:creator>
    <dc:date>2001-08-24T04:11:27Z</dc:date>
    <item>
      <title>WaitForSingleObject</title>
      <link>https://community.intel.com/t5/Software-Archive/WaitForSingleObject/m-p/964389#M22510</link>
      <description>I am writing a mufti-thread program and try coordinate the execution of the main process and a  thread using the CreateEvent, SetEvent and WaitForSingleObject Win32 routines. Both, the main process and the thread, set their own event, when they are ready to receive data from the other. The thread, created by the main process should wait indefinetily.   &lt;BR /&gt;To achieve this I try to use the   &lt;BR /&gt;  &lt;BR /&gt;WaitForSingleObjecth(Event, WAIT_INFINITE)  &lt;BR /&gt;  &lt;BR /&gt;According to the CVF Programmer`I Guide I should use the DFMT and DFWIN modules, but it causes several compiler errors, as the same  routines (CREATETHREAD, WAITFORSINGLEOBJECT, etc) are declared in both. I decided to use the DFWIN routine and declare the WAIT_INFINITE integer parameter (=-1).  &lt;BR /&gt;  &lt;BR /&gt;Inteerestingly, the WAITFORSINGLEOBJECT routine in the thread returns only at evry second time, when the object (hEvent) has been signaled in the main process. Using the Debugger, setting breaks at the  &lt;BR /&gt;   &lt;BR /&gt;SETEVENT(hEvent)  &lt;BR /&gt;  &lt;BR /&gt;and the  &lt;BR /&gt;  &lt;BR /&gt;WaitForSingleObjecth(hEvent, WAIT_INFINITE)  &lt;BR /&gt;  &lt;BR /&gt;result returns for every single event. Setting breaks only one of the above, result "abnormal" return. It seems to me there might be some timing problem?  &lt;BR /&gt;  &lt;BR /&gt;To overcome the above problem the thread waits only for a definite time and if it times out, the WaitForSingleObject routine is called again and again in an infinite loop untill the hEvent object is signaled by the main process.</description>
      <pubDate>Fri, 24 Aug 2001 04:11:27 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/WaitForSingleObject/m-p/964389#M22510</guid>
      <dc:creator>tkibedi</dc:creator>
      <dc:date>2001-08-24T04:11:27Z</dc:date>
    </item>
    <item>
      <title>Re: WaitForSingleObject</title>
      <link>https://community.intel.com/t5/Software-Archive/WaitForSingleObject/m-p/964390#M22511</link>
      <description>DFMT is primarily intended for use in apps which require multithreading only, not full Win32 interfaces. DFWIN contains DFMT and a lot more. The constant in question should be INFINITE (accorging to docs, which is defined in DFWINTY), not WAIT_INFINITE, but its value is -1, so it should work. &lt;BR /&gt; &lt;BR /&gt;Back to essential problem, to me it looks like the order of happening is not quite &lt;BR /&gt;OK. Have in mind that threads are not 100% parallel on a single-processor machine -- they are executed in chunks of code one, then another. The situation you have (WaitForSingleObject succeeds every second time) might be result of  &lt;BR /&gt;something like: &lt;BR /&gt; &lt;BR /&gt;&lt;PRE&gt; 
---SetEvent--&amp;gt;|                                                |--ResetEvent--&amp;gt;...| 
              |---WFSO abandoned----WFSO again entered&amp;amp;leaved--|                  |-WFSO entered&amp;amp;waits 
&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt;Or something similar. You might consider using automatic-reset Events. If you already do... well, I don't know. &lt;BR /&gt; &lt;BR /&gt;HTH &lt;BR /&gt;Jugoslav</description>
      <pubDate>Fri, 24 Aug 2001 22:41:33 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/WaitForSingleObject/m-p/964390#M22511</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2001-08-24T22:41:33Z</dc:date>
    </item>
  </channel>
</rss>

