A SOLUTION OF SMOKERS PROBLEM: by Ryuichi Kishibe, Spring 95

This is a Pull Solution (i.e. the Agents put ingredients on the table only in response to a direct request from Smokers), with at most two doses per ingredient on the table at any one time. [Any problem if we add the restriction of only one dose per ingredient?]
This solution is interesting because it shows how easy the problem becomes if we allow concurrency within each process. Of course, you are not allowed to do the same in your homework.
SHARED VARIABLES
	table		: semaphore	:= 1; /*boolean semaphore*/
	mr, 		  -- Where smokers sleep waiting for matches
	tr, 		  -- Where smokers sleep waiting for tobacco
	wr 		  -- Where smokers sleep waiting for wrapper
	ms, 		  -- Where agents sleep waiting for match requests
	ts, 		  -- Where agents sleep waiting for tobacco requests
	ws		  -- Where agents sleep waiting for wrapper requests
		: semaphore	:= 0; /*blocking semaphore*/
PROGRAM:
	PARBEGIN
		agent-m;
		agent-t;
		agent-w;
		smoker-m;
		smoker-t;
		smoker-w;
	PAREND;

AGENT-M (similar for T and W):
	PARBEGIN
	   LOOP P(ts); P(table); put tobacco; V(table); V(tr); FOREVER; 
	   LOOP P(ws); P(table); put wrapper; V(table); V(wr); FOREVER; 
	PAREND;

SMOKER-M (similar for t and w):
	LOOP
	   think;
	   PARBEGIN
	      BEGIN V(ts); P(tr);END;
	      BEGIN V(ws); P(wr);END; 
	   PAREND;
	   P(table); Pick up Ingredients; V(table); 
	   smoke; 
	FOREVER;