Windows下的信号量 [英] Semaphore under windows

查看:108
本文介绍了Windows下的信号量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在C编程中使用CreateSemaphore()?
您有用于解释该概念的示例代码吗?

请发送给参考....

谢谢您,

How to use CreateSemaphore() in c programming?
Do you have a sample coding for explaining the concept?

Please send it for reference....

Thank you,

推荐答案

1)您可以使用全局变量创建一个简单的信号灯

2)CreateSemaphore详细信息-
http://technology.niagarac.on.ca/courses/ctec1638/win32/CreateSemaphore.htm [^ ]

3)示例(仅样品流)
1) A simple semaphore you can create with a global variable

2) CreateSemaphore details -
http://technology.niagarac.on.ca/courses/ctec1638/win32/CreateSemaphore.htm[^]

3) Example (just sample flow)
MAX_USERS = 25;
HANDLE hSemaphore; 

hSemaphore = CreateSemaphore(NULL, MAX_USERS,
MAX_USERS, "semkey");
..
WaitForSingleObject(hSemaphore, INFINITE);
// do the work 
...
ReleaseSemaphore(hSemaphore, 1);
...



4)您也可以使用互斥量(OpenMutex)(注意:互斥量不是信号量)(互斥量实际上是值为1的信号量.)
(已淘汰)
5)检查此代码是否可以在unix中实现信号量代码
http://www.minek.com/files/unix_examples/semab.html



4) you can use mutex in way too (OpenMutex) (note: Mutex is not semaphore)(A mutex is really a semaphore with value 1.)
(discouraged)
5) Check this for a implementation of semaphore code in unix
http://www.minek.com/files/unix_examples/semab.html
Hope this helps.


这篇关于Windows下的信号量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆