码迷,mamicode.com
首页 > 编程语言 > 详细

线程同步之EVENT

时间:2014-08-14 23:59:16      阅读:509      评论:0      收藏:0      [点我收藏+]

标签:des   style   http   color   java   os   io   strong   

事件可传信给其他线程,表示某些条件现在已具备,比如有可用的消息。

事件可分为手动复位和自动复位,前者可传信给许多同时等待事件的线程而且可以被复位。

自动复位的事件传信给单个等待时间的线程,该事件会自动复位。

Applications can use event objects in a number of situations to notify a waiting thread of the occurrence of an event. For example, overlapped I/O operations on files, named pipes, and communications devices use an event object to signal their completion. 

The following example(From MSDN)uses event objects to prevent several threads from reading from a shared memory buffer while a master thread is writing to that buffer. First, the master thread uses the CreateEvent function to create a manual-reset event object whose initial state is nonsignaled. Then it creates several reader threads. The master thread performs a write operation and then sets the event object to the signaled state when it has finished writing.

Before starting a read operation, each reader thread uses WaitForSingleObject to wait for the manual-reset event object to be signaled. When WaitForSingleObject returns, this indicates that the main thread is ready for it to begin its read operation.



线程同步之EVENT,布布扣,bubuko.com

线程同步之EVENT

标签:des   style   http   color   java   os   io   strong   

原文地址:http://blog.csdn.net/chuchus/article/details/38567423

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!