ResetEvent()的目的; [英] Purpose of ResetEvent();
本文介绍了ResetEvent()的目的;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
ResetEvent()的目的是什么,尽管我们可以使用CreateEvent(),SetEvent()和WaitForSingleObject()函数完成任务?
解决方案
Google是您的朋友,请很好用.
http://msdn.microsoft.com/en-us/library/ms685081 (v = vs.85).aspx [ 解决方案
Google is your friend, use it well.
http://msdn.microsoft.com/en-us/library/ms685081(v=vs.85).aspx[^]
According to MSDN
The ResetEvent function is used primarily for manual-reset event objects, which must be set explicitly to the nonsignaled state. Auto-reset event objects automatically change from signaled to nonsignaled after a single waiting thread is released.
ResetEvent()
is for ''un''SetEvent()
''ing
In your use case you''re obviously using the event singularly, but there are cases where theWaitForSingleObject()
is within a loop and will be called again, normally in a job workerthread scenario (althoughPulseEvent()
may be more appropriate sometimes)
main thread
// pseudo code for(int loop=0;looper<10;looper++) { // add job AddJobToWorkerThread(); // signal a new job is to be done SetEvent(newJobToBeDoneEvent); // and sleep Sleep(10000); }
workerthread
// while(!threadToBeTerminated) { if(WaitForSingleObject(newJobToBeDoneEvent,5000)==WAIT_OBJECT_0) { // do the job we were posted ... // then clear the flag and wait again ResetEvent(newJobToBeDoneEvent); } else break; }
这篇关于ResetEvent()的目的;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文