Click here to Skip to main content
15,881,248 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,

1 solution

1) A simple semaphore you can create with a global variable

2) CreateSemaphore details -[^]

3) Example (just sample flow)
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.)
5) Check this for a implementation of semaphore code in unix
Hope this helps.
Share this answer

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