Path: utzoo!attcan!uunet!mcvax!ukc!stc!datlog!dlhpedg!cpm From: cpm@datlog.co.uk (Paul Merriman) Newsgroups: comp.os.minix Subject: Re: Semaphores Message-ID: <785@dlhpedg.co.uk> Date: 9 Jun 88 15:35:18 GMT References: <1832@silver.bacs.indiana.edu> Sender: news@dlhpedg.co.uk Reply-To: cpm@.co.uk (Paul Merriman) Organization: FSD@Data Logic Ltd, Queens House, Greenhill Way, Harrow, London. Lines: 35 In response to the request for a simple test to semaphores :- As well as the Producer/Consumer type problem semaphores are useful for providing synchronization between two or more processes. A simple test and illustration of this use would be to create two (very !) short prcesses - one which prints odd numbers and the other even numbers. Create two semaphores (ODD and EVEN ?) and initialize them to 1 and 0 respectively. Then 'wait's and 'signal's can be used to ensure that the processes output their numbers alternately (i.e. synchronizes the processes ) e.g. Process 1 --------- Wait(ODD) Print next odd number in sequence (1,3,5..) Signal(EVEN) Process 2 --------- WAIT(EVEN) Print next even number in sequence (2,4,6..) SIGNAL(ODD) While I'm on the subject I was interested to see that you implemented the semaphores in mm. A nicer, but harder idea would be to put it in the fs and then use file names to name your semaphores !