Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 6 Apr 1999 11:31:21 -0700
From:      "Brian O'Shea" <boshea@ricochet.net>
To:        Aldrin L <aldrin@americasnet.com>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Semaphores
Message-ID:  <19990406113121.J2844@localdomain>
In-Reply-To: <Pine.BSF.4.05.9904061145220.353-100000@athome.logicStudios.org>; from Aldrin L on Tue, Apr 06, 1999 at 11:46:35AM -0300
References:  <Pine.BSF.4.05.9904061145220.353-100000@athome.logicStudios.org>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Apr 06, 1999 at 11:46:35AM -0300, Aldrin L wrote:
> Hello
> 
> 	I've wondering which would be the best way to do semaphores
> without the need of recompiling my kernel for SysV IPC. Does anyone have
> any idea/suggestion? :]
> 
> 	Comments welcome. :]
> 
> 	done, Aldrin Leal <aldrin@americasnet.com>
>   
> 
> 
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message
> 

There are a few options depending on what you need semaphores for.
If you need process-shared semaphores (ones that can be used to
synchronize multiple processes, as opposed to just threads in the same
process), then you will need to use the SysV semaphore interface (so
you will need to compile a knernel with support for them).

If you just need simple binary semaphores to synchronize threads in a
user-threaded process then pthread mutexes may suit your needs.  To use
them, include <pthread.h> and link against the libc_r library instead
of libc (either with the -lc_r linker option or with the -pthread
compiler option, which is FreeBSD-specific).  See the man page on
pthread(3) for an overview of the pthread library functions.

Unfortunately the POSIX semaphore library functions (sem_init(),
sem_wait(), sem_post(), etc.) don't seem to exist on my 3.1-RELEASE
system or any of the previous releases that I have used (going back to
2.2.1-R), despite the fact that the header file <semaphore.h> exists
containing their prototypes.  This interface has many of the features
of SysV semaphores (for instance if you need to initialize a semaphore
to valued greater than 1).  If these library functions are added in the
future, they may be what you are looking for.

Linux has an implementation of POSIX semaphores, although process-shared
semaphores are not supported.  I have run Linux programs on FreeBSD
(under Linux emulation) that I wrote using the POSIX threads functions
and they worked just fine (although I didn't test them extensively).

There may be more options.  These are just the ones that I have come
across.

Good luck,
-brian

p.s.  Is there any particular reason for why you don't want to recompile
your kernel?

-- 
Brian O'Shea
boshea@ricochet.net


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19990406113121.J2844>