🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.amiga.tech
Article #5313

Amiga semaphores (HELP!)

#5313
From: Jim_Garrison
Date: Fri, 14 Sep 1990 15:51
66 lines
2352 bytes
Hello,

I've trying to use Amiga Semaphores, as a mechanism to let only one program
access a particular resource at a time.  I'm using the Amiga Programmers
Reference by Eugene Mortimer, as a reference for using the semaphores.  I
seem to recall that there is either some problem with the description of
semaphores in this book, or there are problems with the way Amiga semaphores
work.  I'm using an A2500 with Amigados 1.3 and Lattice 5.05 C compiler.

I've provided some code which seems like it should work, but doesn't.  If
two copies of this program are run at the same time, the first copy should
get the resource, and the second copy should wait until the first copy is
done.  Right now, FindSemaphore("test1") returns null in both programs, so
they both access the resource, and mess each other up.  Am I using
FindSemaphore() wrong, or am I using AddSemaphore() incorrectly?  I'd sure
appreciate any light shed on this.

Thanks in advance,


Jim Garrison (jimg@hpiatmh)
Hewlett Packard
Industrial Applications Center
(408) 746-5349


Sample program follows:


/* IPC.C - This is a test program, so I can see how Amiga semaphores work.
 *
 * 09/13/90 - Created by Jim Garrison.
 */

#include <stdio.h>
#include <libraries/dosextens.h>
#include <exec/semaphores.h>
#include <exec/memory.h>

main()
{
   struct SignalSemaphore *sem;
   int error;

   sem = FindSemaphore("test1");
   if (!sem)
   {
      sem = AllocMem(sizeof(struct SignalSemaphore), MEMF_PUBLIC | MEMF_CLEAR);
      printf("Making a semaphore\n");
      sem->ss_Link.ln_Name = "test1"; 
      sem->ss_Link.ln_Pri = 1; 
      error = AddSemaphore(sem);
      printf("Addsem error = %d\n", error);
   }
   else
      printf("Got an existing semaphore\n");
   ObtainSemaphore(sem);
   printf("Pausing ....\n");
   
/* Do something with some resource. */

   ReleaseSemaphore(sem);
   printf("Done\n");
   
}
Technical Details
Message-ID: <2290004@hp-ptp.HP.COM>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!aplcen!uakari.primate.wisc.edu!sdd.hp.com!hplabs!hpl-opus!hpccc!hpcc01!hp-ptp!jimg

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!aplcen!uakari.primate.wisc.edu!sdd.hp.com!hplabs!hpl-opus!hpccc!hpcc01!hp-ptp!jimg
From: jimg@hp-ptp.HP.COM (Jim_Garrison)
Newsgroups: comp.sys.amiga.tech
Subject: Amiga semaphores (HELP!)
Message-ID: <2290004@hp-ptp.HP.COM>
Date: 14 Sep 90 15:51:38 GMT
Organization: HP Pacific Technology Park - Sunnyvale, Ca.
Lines: 66