线程同步简单问题~小白求助~

zxczxcvvvvv 2013-07-01 10:48:37
我的问题是关于这个函数
WaitForSingleObject(
HANDLE hHandle,
DWORD dwMilliseconds
);
WaitForSingleObject 函数用来检测 hHandle 事件的信号状态,当函数的执行时间超过 dwMilliseconds 就返回,但如果参数 dwMilliseconds 为 INFINITE 时函数将直到相应时间事件变成有信号状态才返回。
这是我在网上搜索到的用法,我想请教一下,什么叫做事件变成有信号状态?
谢谢大家~
...全文
152 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxczxcvvvvv 2013-07-01
  • 打赏
  • 举报
回复
引用 5 楼 adlay 的回复:
1. Mutex, 没有现成拥有它的时候处于有信号状态. 有现成拥有它的时候处于无信号状态. A mutex object is a synchronization object whose state is set to signaled when it is not owned by any thread, and nonsignaled when it is owned 2. Semaphore, 内部计数大于 0 的时候处于有信号状态. 为 0 的时候处于无信号状态. A semaphore object is a synchronization object that maintains a count between zero and a specified maximum value. The count is decremented each time a thread completes a wait for the semaphore object and incremented each time a thread releases the semaphore. When the count reaches zero, no more threads can successfully wait for the semaphore object state to become signaled. The state of a semaphore is set to signaled when its count is greater than zero, and nonsignaled when its count is zero. DWORD 就是 unsigned int 为了让系统去回调那个函数.
非常感谢~我想请问一下这些资料也是在上面那位仁兄说的windows核心编程中的吗?
www_adintr_com 2013-07-01
  • 打赏
  • 举报
回复
现成->线程
www_adintr_com 2013-07-01
  • 打赏
  • 举报
回复
1. Mutex, 没有现成拥有它的时候处于有信号状态. 有现成拥有它的时候处于无信号状态. A mutex object is a synchronization object whose state is set to signaled when it is not owned by any thread, and nonsignaled when it is owned 2. Semaphore, 内部计数大于 0 的时候处于有信号状态. 为 0 的时候处于无信号状态. A semaphore object is a synchronization object that maintains a count between zero and a specified maximum value. The count is decremented each time a thread completes a wait for the semaphore object and incremented each time a thread releases the semaphore. When the count reaches zero, no more threads can successfully wait for the semaphore object state to become signaled. The state of a semaphore is set to signaled when its count is greater than zero, and nonsignaled when its count is zero. DWORD 就是 unsigned int 为了让系统去回调那个函数.
赵4老师 2013-07-01
  • 打赏
  • 举报
回复
《Windows核心编程》 About Synchronization To synchronize access to a resource, use one of the synchronization objects in one of the wait functions. The state of a synchronization object is either signaled or nonsignaled. The wait functions allow a thread to block its own execution until a specified nonsignaled object is set to the signaled state. The following are other synchronization mechanisms: overlapped input and output asynchronous procedure calls critical section objects interlocked variable access
zxczxcvvvvv 2013-07-01
  • 打赏
  • 举报
回复
引用 1 楼 adlay 的回复:
根据 Handle 的类型不同, "有信号状态"有不同的含义
我是在一个生产者消费者的代码中看到的,这里HANDLE有Mutex和Semaphore两种,请问那对于这两种分别是什么含义呢?
zxczxcvvvvv 2013-07-01
  • 打赏
  • 举报
回复
另外我还有一个问题,我在看孙鑫老师的教学中,一些函数,比如 DWORD WINAPI ThreadProc1(LPVOID lpParameter) { cout<<""; return 0; } 我想问一下问什么是DWORD类型的? 另外在创建线程的函数 CreateThread(NULL, 0, Fun, NULL, 0, NULL); 这里Fun是一个函数,我想问一下函数作为参数是实现了什么作用?
www_adintr_com 2013-07-01
  • 打赏
  • 举报
回复
根据 Handle 的类型不同, "有信号状态"有不同的含义

64,282

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧