A semaphore is a data structure that maintains a set of permits that have to be acquired by competing threads. Semaphores can therefore be used to control how many threads access a critical section or resource simultaneously. Hence the constructor of takes as first parameter the number of permits the threads compete about. Each invocation of its methods tries to obtain one of the available permits. The method without any parameter blocks until the next permit gets available. Later on, when the thread has finished its work on the critical resource, it can release the permit by invoking the method on an instance of Semaphore.
No comments:
Post a Comment