CS322: Concurrent Processes and Programming

Semaphores

  1. One approach to dealing with the critical section problem is the use of a facility first proposed by Dijkstra called a semaphore.

  2. In practice, we often use one of several possible generalizations of the basic semaphore.

  3. Examples of using semaphores to solve classical problems:

  4. As an aside, we also note another use for semaphores. They can be used with PARBEGIN .. PAREND to enable any precedence graph to be realized.

    Example: Our earlier precedence graph:

    	S1  
    	| \ 
    	S2 S3
    	|  / \
    	S4    S5
    	  \  /
    	   S6
    
    	S1;				-- all semaphores initially 0
    	PARBEGIN
    	    BEGIN S2; V(a); END;	-- semaphore a guarantees S2 precedes S4
    	    BEGIN S3; V(b); V(c); END;	-- semaphores b, c guarantee that S3
    	    BEGIN P(a); P(b); S4; END;	-- precedes both S4 and S5
    	    BEGIN P(c); S5; END;
    	PAREND;
    	S6;
    

  5. Problems with the semaphore solution to the critical-section problem:


$Id: concurrency6.html,v 1.3 1998/03/18 21:27:06 senning Exp $

These notes were written by Prof. R. Bjork of Gordon College. In February 1998 they were edited and converted into HTML by J. Senning of Gordon College.