Underline version of semaphore functions
Daniel Eischen
deischen at freebsd.org
Tue Jan 5 14:37:04 UTC 2010
On Tue, 5 Jan 2010, David Xu wrote:
> I saw underline version of semaphore functions in
> libc/include/namespace.h:
>
> #define sem_close _sem_close
> #define sem_destroy _sem_destroy
> #define sem_getvalue _sem_getvalue
> #define sem_init _sem_init
> #define sem_open _sem_open
> #define sem_post _sem_post
> #define sem_timedwait _sem_timedwait
> #define sem_trywait _sem_trywait
> #define sem_unlink _sem_unlink
> #define sem_wait _sem_wait
>
>
> but libc never has them:
Yes, because libpthread has them and the thread library
was needed in order to provide semaphores. These single
underscore functions are for libc internal usage so that
libthr (libpthread) may know the difference between
semaphores created/used by libc and those created/used
by an application. The provider of semaphores (and
mutexes, condvars, etc) may need to know who created
and uses these objects (libc or application), so for
example on a fork() or perhaps thread_safe_fork()
all those objects created by libc can be automatically
reinitialized. Or perhaps so that we know whether
to delay thread cancellation until a thread releases
these internal locks.
--
DE
More information about the freebsd-threads
mailing list