POSIX semaphores?

Daniel Eischen eischen at vigrid.com
Fri Jan 30 06:11:15 PST 2004


On Fri, 30 Jan 2004, Andrey Chernov wrote:

> Could anybody enlighten me, please?
> 
> 1) What is current status of POSIX semaphores? Are they at the production
> quality? Are they better implemented than SYSV ones?
> 2) What is kernel option to turn them on? Why I don't find it in NOTES or
> GENERIC?

You need option P1003_1B_SEMAPHORES.  It's in sys/conf/NOTES.

> The reason why I ever ask is that some ports try to sense POSIX semaphores
> at configure stage (looking for sem_init()) and then compiled program
> fails with "Unknown system call" diagnostic.

They must be trying to use shared semaphores which currently don't
work across processes (unless they are forked and semaphore is
created before the fork).  The problem is that semaphores (and
mutexes, condition variables, etc) are all pointers to an
allocated structure.  You can't place this (the pointer) in
shared memory and have processes other than the creating
process access it.  This probably won't be fixed until
6.0 because we'll need to change these synchronization
types to be the actual structures instead of pointers
(breaking binary compatibility).

So we do support semaphores, but not pshared semaphores
even though the library call honors pshared.  And if you
do try to use a pshared semaphore, then the kernel support
(P1003_1B_SEMAPHORES) has to be there.

-- 
Dan (currently reworking semaphores)



More information about the freebsd-current mailing list