Shared Libraries -- experiences etc.
Gordon Cross
crossgl at ingr.com
Thu Feb 2 19:08:30 AEST 1989
In article <81584 at felix.UUCP> martin at felix.UUCP (Martin McKendry) writes:
>
> o) Are semaphores the only appropriate technique for implementing
> mutual exclusion on small objects? For example, if I had a
> large number (say, 2000) of objects that were small (say, 20 bytes),
> and I wanted to put locks on each object. Assume that there
> are many processes active in the total structure, but they
> tend not to interfere with one another. Are semaphores the
> mechanism of choice for this problem? It seems like a lot
> of overhead to allocate one semaphore per record.
Most machines have an instruction called a "test and set" operation. These
instructions allow you to test the current value of a memory location and
simultaneously (ie. non-interruptable) set a bit in that location. Using
this instruction you can implement what is called a software lock. This
approach for locking many small data items (presumably kept in memory that
is shared between multiple processes) is MUCH MUCH better than semaphores
(even if it was possible to allocate 20,000 of them). In System V there is
no routine already provided to use software locks (I don't know about BSD
and others) so I had to write my own in assembler (quite small just a couple
of instructions).
--
Gordon Cross UUCP: uunet!ingr!crossgl "all opinions are
111 Westminister Way INTERNET: crossgl at ingr.com mine and not those
Madison, AL 35758 MA BELL: (205) 772-7842 of my employer."
More information about the Comp.unix.questions
mailing list