From: Rob McCool <robm@netscape.com> Newsgroups: netscape.devs-nsapi Subject: Re: Semaphore usage instead of criticals Date: Wed, 07 Aug 1996 15:04:57 -0700 Doug Donohoe wrote: > A while back Jan Zawadzki suggested I use semaphores instead of > critical sections (for performance reasons). > > I tried semaphores, but they never seemed to block other > threads (I tested this by putting in sleep calls). However, the > creation of the semaphore never failed. > > My code for both critical and semaphore use is below. Does anyone > have an idea why the semaphore part doesn't work? What is > the "name" parameter to sem_init() supposed to be?The semaphores in base/sem.h are misnamed. They're really interprocess locks. If two threads in the same process go for the same lock they'll both get it.
You'll want to stick with critical sections.
name and number determine what the file name for the lock is. They're used to distinguish between different plugins' semaphores.
-- Rob McCool, robm@netscape.com http://home.netscape.com/people/robm/ Stunt Programmer, Netscape Communications Corporation It was working ten minutes ago, I swear...Reproduced by permission of the author.