Path: utzoo!dciem!nrcaer!scs!spl1!laidbak!att!pacbell!ames!mailrus!tut.cis.ohio-state.edu!ukma!gatech!udel!mmdf From: Bruno_Kieba.SBDERX@xerox.com Newsgroups: comp.os.minix Subject: Re: Semaphores Message-ID: <2864@louie.udel.EDU> Date: 3 Jun 88 16:44:23 GMT Article-I.D.: louie.2864 Sender: mmdf@udel.EDU Lines: 31 Pat, I would interested to see the source code of your semaphore implementation. I have myself implemented semaphores in MINIX but not as sophisticated as yours. I wrote it for educational purpose only. I implemented mine in the file system of MINIX (because this is one area I am most familiar with) with three system calls seminit, semwait and semsignal. To test it, I created a dummy file called 'data'. First I do a 'initsem' (calling seminit) to initialise two semaphores SPACE and WORK. A producer (running in the background) does a semwait on a semaphore SPACE, opens the file 'data', writes a number contained in a variable into the file, increments the number contained in the variable by two for the next round, closes the file and does a semsignal on a WORK semaphore. A consumer does a semwait on the WORK semaphore, opens the file 'data', retrieves the number from it, displays it to the terminal screen, closes the file and does a semsignal on the SPACE semaphore. A consumer also runs in the background. Both, producers and consumers need to run in the background otherwise they cannot be killed while they are executing. The kill signal doesn't get caught. The implementation works for one or more producers and consumers. Processes waiting on a semaphore are blocked on the appropriate semaphore (FIFO) queue and awaken when there is work to do (after a signal on the appropriate semaphore). I used the 'trick' of Andy to do the implementation. The only problem with my implementation is that any process can initialise the WORK and SPACE semaphores and thus totally screw up the blocked processes waiting on them. I read about the concept of keys UNIX uses. Maybe this is one way to do it. I am interested in the way you implemented your semaphores. It will also help me to get more familiar with the memory manager. The back pages of PC XENIX documentation show a few examples of semaphores in order to test them. The UNIX System Programming book from Keith Haviland and Ben Salama (1987 Addison-Wesley Publishing Company, Inc.) has some examples for shared memory with shmget and shmop system calls. Good to look at. Hoping that you can send me the source, Bruno