Path: utzoo!utgpu!watserv1!watdragon!lion!ccplumb From: ccplumb@lion.waterloo.edu (Colin Plumb) Newsgroups: comp.sys.amiga.tech Subject: Re: Semaphores Keywords: Exec Semaphore Message-ID: <20813@watdragon.waterloo.edu> Date: 12 Feb 90 21:09:55 GMT References: <00253.AA00253@miroc> Sender: daemon@watdragon.waterloo.edu Reply-To: ccplumb@lion.waterloo.edu (Colin Plumb) Organization: U. of Waterloo, Ontario Lines: 21 In article <00253.AA00253@miroc> caw@miroc.UUCP (Christopher A. Wichura) writes: > I am about to start fooling with semaphores for a program I am working on > and have run across something that bothers me. There is no opposite to > InitSemaphore() that I can find. When my program wants to exit, which > includes closing down the semaphore, what do I do? Is it `safe' to simply > drop the semaphore if all ObtainSemaphore()s have been matched by an equal > number of ReleaseSemaphore()s? This will be a private semaphore so I don't > have to worry about removing it from the system lists, or at least so it > would seem. It is safe. A semaphore is just a private data structure manipulated by Exec which you have to allocate. Exec only manipulates it on an explicit call from you, so as long as no processes are dangling off it (which would result in unrecoverable resources, as the processes would never run and exit), if you can guarantee that nobody will ever again pass the semaphore to one of the Exec routines (which is true in your case), you can deallocate it like any other piece of memory. InitSemaphore() just sets up the data structure to the right value; there is no corresponding need to clear memory before deallocating it. -- -Colin