Article View: amiga.prog
Article #1Signal Semaphores
From: Russell McOrmond
Date: Tue, 21 Jul 1992 03:26
Date: Tue, 21 Jul 1992 03:26
61 lines
2306 bytes
2306 bytes
I'm wondering if anyone has done extensive work with SignalSemaphores under
2.04 (V37) that could let me know what I'm doing wrong with my use of them.
I just put a 'Forbid()/Permit()' pair around all the things
that 'should' have been protected by an ObtainSemaphore/ReleaseSemaphore
pair in some multi-threaded code, and a large number of bugs just 'went away'.
Since I'd rather that ALL tasks didn't wait, and only those wanting access
to these structures, I'd rather get things working.
The program in question runs many different processes, all of which share
the same global variables. When accessing any of the structures, I had put
semaphore arbitration around the calls. Here's some 'example' code from what
I'm doing:
typedef struct config_struct {
struct slave_struct mainSlave;
/* Slaves */
struct SignalSemaphore listLock;
....
if((myconfig=AllocMem(sizeof(config),MEMF_CLEAR))) {
....
InitSemaphore(&myconfig->listLock);
....
int CountSlaves()
{
slave *aslave;
int i;
i=0;
ObtainSemaphore(&myconfig->listLock);
Forbid();
FOREACH_LIST_UNSAFE(&myconfig->slaves,aslave)
if(aslave!=myconfig) i++;
END_LIST_UNSAFE;
Permit();
ReleaseSemaphore(&myconfig->listLock);
return(i);
}
All other calls are exactly the same as the Semaphore calles above.
As mentioned, without the Forbid()/Permit() pair around the calls, everything
crashes very quickly. P.S. Yes, the InitSemaphore happens very soon after
the memory is allocated, and long before any other semaphore operations are
called.
Thanks for any help. The net has always been great for pointing out my
stupid errors so I can quickly move on to getting some real work done! ;-)
---
Opinions expressed in this message are my Own. I represent nobody else.
Russell McOrmond rwm@Atronx.OCUnix.On.Ca Net Support:(613) 230-2282(V.32Bis)
FidoNet 1:163/109 Amiga-Fido 1:1/109 Current WELMAT 'keeper of sources'.
Technical Details
Message-ID:
<rwm.711692783@atronx.OCUnix.On.Ca>Path:
arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!torn!cunews!revcan!sidus!qube!atronx.OCUnix.On.Ca!rwmShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!cs.utexas.edu!torn!cunews!revcan!sidus!qube!atronx.OCUnix.On.Ca!rwm From: rwm@atronx.OCUnix.On.Ca (Russell McOrmond) Message-ID: <rwm.711692783@atronx.OCUnix.On.Ca> Date: 20 Jul 92 22:26:23 EST Newsgroups: amiga.prog,comp.sys.amiga.programmer Subject: Signal Semaphores Lines: 62