Path: utzoo!attcan!uunet!decwrl!ogicse!pdxgate!eecs!griffith From: griffith@eecs.cs.pdx.edu (Michael Griffith) Newsgroups: comp.sys.amiga.tech Subject: Re: Amiga semaphores (HELP!) Message-ID: <142@pdxgate.UUCP> Date: 24 Sep 90 03:44:51 GMT References: <2290004@hp-ptp.HP.COM> <2290006@hp-ptp.HP.COM> Sender: news@pdxgate.UUCP Lines: 50 jimg@hp-ptp.HP.COM (Jim_Garrison) writes: >Hello again, >I tried adding the LocalAddSemaphores() which John Suchs suggested to my >program. It still doesn't work! Please note that I am using NAMED semaphores >here, maybe that's what's causing my problems. Even after I have run this >program once (or more) FindSemaphore(name) still returns NULL. Do named >semaphores work? Or am I still not initializing my named semaphore >incorrectly? What I want to happen is that if two of these programs are run >/* IPC.C - This is a test program, so I can see how Amiga semaphores work. > * > * 09/13/90 - Created by Jim Garrison. > * 09/18/90 - Added in LocalAddSemaphore() suggested by John Suchs. > */ >void LocalAddSemaphore(struct SignalSemaphore *SignalSemaphore, char *name) >{ > SignalSemaphore->ss_Link.ln_Type=NT_SIGNALSEM; > SignalSemaphore->ss_Link.ln_Name = name; > SignalSemaphore->ss_Link.ln_Pri = 1; > InitSemaphore(SignalSemaphore); > Forbid(); > Enqueue(&SysBase->SemaphoreList,SignalSemaphore); > Permit(); >} It seems to me that your problem is thus: You are temporarily allocating space (for the duration of your program) for the name string in your node, but rather than making a permanent copy you are just setting the pointer ln_Name to point to it. Your program then terminates, freeing the memory allocated for the string. Something else uses this memory, overwriting your string and making it impossible for FindSemaphore to locate it. Try the following inserted in place of the line where you set ln_Name: SignalSemaphore->ss_Link.ln_Name = AllocMem(sizeof(char)*(strlen(name)+1), MEMF_PUBLIC); strcpy(SignalSemaphore->ss_Link.ln_Name,name); /* I know this could be more elegant, and you should check to make sure the allocation is succesful, but since it's just a test... ;) */ Anyways, hope that helps. | Michael Griffith | If I had an opinion it certainly | | griffith@eecs.ee.pdx.edu | wouldn't be the same one as | | ...!tektronix!psueea!eecs!griffith | Portland State University anyways. |