Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!julius.cs.uiuc.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!hplabs!hpcc05!hp-ptp!jimg From: jimg@hp-ptp.HP.COM (Jim_Garrison) Newsgroups: comp.sys.amiga.tech Subject: Re: Amiga semaphores (HELP!) Message-ID: <2290009@hp-ptp.HP.COM> Date: 27 Sep 90 14:47:05 GMT References: <2290004@hp-ptp.HP.COM> Organization: HP Pacific Technology Park - Sunnyvale, Ca. Lines: 93 Yahoo, thanks to Peter Xrbfk, I now have working Amiga semaphores. I guess that my problem was that FindSemaphore() doesn't work either. I have included Peter's example program which works fine for me. As someone else mentioned, I think it might be a good idea to include this information in the Amiga introduction. Thank you all for your help, Jim Garrison Hewlett Packard jimg@hpiatmh (408) 746-5349 >Hi, Jim. > >I suppose it was I who tried to post this to you at the wrong address. > >This works on my A500, ie. creates the semaphore once, and finds it >afterwards. It did not work with FindSemaphore() which seems to have >a slight hitch in that it expects the name in A1 and not in A0 as indicated >in the .fd file. One could consider this to be an error of the compiler >makers who have not noticed this. > >With Aztec C 3.4 this program does the trick, but it shouldn't >be compiler dependent. > >I hope this works for you too. > > > - Peter (poe@daimi.aau.dk) > ---- cut here ---- /* sem.c */ /* Created 26-Sep-90 by Peter Xrbfk. This works on my A500 (KS 33.180 / WB 34.20) */ #include "exec/types.h" #include "exec/semaphores.h" #include "exec/execbase.h" #include "exec/memory.h" #include "stdio.h" struct Node *FindName(); void *AllocMem(); char *strcpy(); extern struct ExecBase *SysBase; /* Define private version of FindSemaphore() because FindSemaphore() really expects the namepointer in A1 and not in A0 as indicated in the .fd files */ #define FindSem(s) (struct SignalSemaphore *)FindName(&SysBase->SemaphoreList,s) main() { struct SignalSemaphore *ss; char *str; if(!(ss = FindSem("MySem"))) { printf("didn't find semaphore\n"); ss = (struct SignalSemaphore *) AllocMem((long)sizeof(struct SignalSemaphore), MEMF_PUBLIC|MEMF_CLEAR); /* assume ok */ InitSemaphore(ss); str = AllocMem(10L,MEMF_PUBLIC); ss->ss_Link.ln_Name = strcpy(str,"MySem"); ss->ss_Link.ln_Pri = 0; printf("adding it\n"); /* add it */ Forbid(); AddTail(&SysBase->SemaphoreList,ss); Permit(); printf("semaphore created and added\n"); } /* use it for something */ ObtainSemaphore(ss); printf("bla\n"); ReleaseSemaphore(ss); }