Semaphore
A semaphore is a protected variable or abstract data type that constitutes a constitutes a classic method of controlling access by several processes to a common resource in a parallel programming environment. It generally takes one or two forms: binary and counting. A binary semaphore is a simple true and false that controls access to single resource.
There is one Pascal example is defined below
procedure V (S : Semaphore);
begin (* Atomic operation: increment the semaphore. *) S := S + 1; end; (* Atomic operation: decrement the semaphore. *) procedure P (S : Semaphore); begin (* Whole operation is atomic *) repeat Wait(); until S > 0; S := S - 1; end;Reference
Treese, GW & Stewart, LC 2003, Designing systems for Internet commerce, 2nd edn, Addison-Wesley, Boston, MA.

Wow Vaibhavi I can understand about the semaphore but I m bit of confuse about the variable u used in the example!!can u plz explain more about it!!!
ReplyDeleteK Dong...As per ur comment i am explaining u abt my programme variables are: The counting semaphore concept can be extended with the ability to claim or return more than one "unit" from the semaphore. a technique implemented in UNIX. The modified V and P operations would be as follows:
ReplyDeleteS is the number of units of the resource that have not been claimed, P operation wastes time or sleeps until a resource controlled by the semaphore becomes available, V operation is the inverse: it makes a resource available again after the process has finished using it.