[comp.sys.amiga] Question about ReleaseSemaphore

valentin%cbmvax.uucp@cunyvm.cuny.edu (12/06/89)

In article <3156@hub.UUCP> panzer@cornu.ucsb.edu (Panzer) writes:
>
>What happens if a task ReleaseSemaphore()'s a semaphore which another
>task had previously ObtainSemaphore()'d?  The semaphore structure
>has a field for the owner of the semaphore; would changing this field
>prior to the release be necessary or desirable?

These comments are non Amiga specific; the principles of computer science simply

don't allow you to release something you don't own. This is true for memory,
file handles, locks and certainly semaphores. Tranfer of ownership is tricky
and in some cases illegal.

What you seem to need is "private semaphores". These semaphores are basically
owned by one task which can modify the count, but other tasks can only read the
count.

You are better off implementing your mutual-exclusion/synchronising mechanism
using the Signal() and Wait() functions rather than changing the internal
fields in the SignalSemaphore structure while it is being used. Needless to say,

if you hack the internal structure, your code will fail on future versions of
the operating system.

Valentin
--
The Goddess of democracy? "The tyrants     Name:    Valentin Pepelea
may distroy a statue,  but they cannot     Phone:   (215) 431-9327
kill a god."                               UseNet:  cbmvax!valentin@uunet.uu.net

             - Ancient Chinese Proverb     Claimer: I not Commodore spokesman be