Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How to use CreateSemaphore() in c programming?
Do you have a sample coding for explaining the concept?

Please send it for reference....

Thank you,
Posted

1 solution

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) 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.
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900