本文介绍了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,
推荐答案
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下的信号量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!