Semaphore objects are used to control the number of instances running and synchronize between multiple processes rather than multithread. It behaves as if Mutex but the maximum number of instances can be set while creating semaphore.
In this example, I have written one application using Semaphore. It will allow running of the same application to the maximum of 3 times. After that if you try to run the same application, then it will display the message " You have reached running the maximum number of instances of this application." and then it will exit.
For more details, visit at http://www.softwareandfinance.com/Visual_CPP/MultiThread_Semaphore.html