semaphores, thread-safe alloc wrappers

From: Gary Shea <shea_at_nospam.org>
Date: Mon Mar 06 1995 - 15:54:10 PST

The thread-synchronization tools finally seem to be working.

Check 'em out:
ftp://ftp.xmission.com/pub/users/s/shea/tsema.tz

The readme has an annotated manifest, duplicated below:

        include/slock.h // spinlock def'ns
        include/libsem.h // fixed-length-queue sema def'ns
        include/tsafe.h // alloc/free wrapper def'ns
        include/tsema.h // user semaphore def'ns
        include/sys/tsleep.h // tsleep/twake sys calls

        libc/slock.c // spinlock implementations
        libc/libsem.c // fixed-length-queue sema implementation
        libc/tsafe.c // alloc/free wrapper functions
        libc/tsema.c // user semaphore implementation
        libc/mach/slockasm.s // spinlock test'n'set
        os/kern/tsleep.c // tsleep/twake implementation

        /gts/libsem/makefile // test code
        /gts/libsem/tl.c

        /gts/tsema/makefile // test code
        /gts/tsema/ts.c

        ../d.133 // patches for clean vsta.1.3.3

The tsema semaphore implementation is much simpler than
the original -- at this point it's little more than
libsem with the data structures hidden and no limit on the
number of threads in the queue. The cost is a thread-safe
malloc every time a thread must be queued.

If you want the fastest possible semaphore or need to allocate
the semaphore statically, AND you can bound the max number of threads
the semaphore will need to queue, use the libsem implementation.
Otherwise the tsema implementation is a bit simpler.

The alloc/free wrappers are protected by a libsem semaphore.
Its queue size is configurable BEFORE any wrapper function
has been called. Threads beyond the queue size are put to
sleep until there's queue space.

Now I finally get to start working on the asynchronous buffer cache!

        Gary
Received on Mon Mar 6 15:14:37 1995

This archive was generated by hypermail 2.1.8 : Thu Sep 22 2005 - 15:12:17 PDT