<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- Copyright (C) 2003 Red Hat, Inc. -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- This material may be distributed only subject to the terms -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- and conditions set forth in the Open Publication License, v1.0 -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- or later (the latest version is presently available at -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- http://www.opencontent.org/openpub/). -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- Distribution of the work or derivative of the work in any -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- standard (paper) book form is prohibited unless prior -->
|
<!-- permission is obtained from the copyright holder. -->
|
<!-- permission is obtained from the copyright holder. -->
|
<HTML
|
<HTML
|
><HEAD
|
><HEAD
|
><TITLE
|
><TITLE
|
>Synchronization [POSIX Section 11]</TITLE
|
>Synchronization [POSIX Section 11]</TITLE
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
><meta name="MSSmartTagsPreventParsing" content="TRUE">
|
<META
|
<META
|
NAME="GENERATOR"
|
NAME="GENERATOR"
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
|
"><LINK
|
"><LINK
|
REL="HOME"
|
REL="HOME"
|
TITLE="eCos Reference Manual"
|
TITLE="eCos Reference Manual"
|
HREF="ecos-ref.html"><LINK
|
HREF="ecos-ref.html"><LINK
|
REL="UP"
|
REL="UP"
|
TITLE="POSIX Standard Support"
|
TITLE="POSIX Standard Support"
|
HREF="posix-standard-support.html"><LINK
|
HREF="posix-standard-support.html"><LINK
|
REL="PREVIOUS"
|
REL="PREVIOUS"
|
TITLE="Data Interchange Format [POSIX Section 10]"
|
TITLE="Data Interchange Format [POSIX Section 10]"
|
HREF="posix-data-interchange-format.html"><LINK
|
HREF="posix-data-interchange-format.html"><LINK
|
REL="NEXT"
|
REL="NEXT"
|
TITLE="Memory Management [POSIX Section 12]"
|
TITLE="Memory Management [POSIX Section 12]"
|
HREF="posix-memory-management.html"></HEAD
|
HREF="posix-memory-management.html"></HEAD
|
><BODY
|
><BODY
|
CLASS="SECT1"
|
CLASS="SECT1"
|
BGCOLOR="#FFFFFF"
|
BGCOLOR="#FFFFFF"
|
TEXT="#000000"
|
TEXT="#000000"
|
LINK="#0000FF"
|
LINK="#0000FF"
|
VLINK="#840084"
|
VLINK="#840084"
|
ALINK="#0000FF"
|
ALINK="#0000FF"
|
><DIV
|
><DIV
|
CLASS="NAVHEADER"
|
CLASS="NAVHEADER"
|
><TABLE
|
><TABLE
|
SUMMARY="Header navigation table"
|
SUMMARY="Header navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TH
|
><TH
|
COLSPAN="3"
|
COLSPAN="3"
|
ALIGN="center"
|
ALIGN="center"
|
>eCos Reference Manual</TH
|
>eCos Reference Manual</TH
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="posix-data-interchange-format.html"
|
HREF="posix-data-interchange-format.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="80%"
|
WIDTH="80%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
>Chapter 31. POSIX Standard Support</TD
|
>Chapter 31. POSIX Standard Support</TD
|
><TD
|
><TD
|
WIDTH="10%"
|
WIDTH="10%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="bottom"
|
VALIGN="bottom"
|
><A
|
><A
|
HREF="posix-memory-management.html"
|
HREF="posix-memory-management.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"></DIV
|
WIDTH="100%"></DIV
|
><DIV
|
><DIV
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><H1
|
><H1
|
CLASS="SECT1"
|
CLASS="SECT1"
|
><A
|
><A
|
NAME="POSIX-SYNCHRONIZATION">Synchronization [POSIX Section 11]</H1
|
NAME="POSIX-SYNCHRONIZATION">Synchronization [POSIX Section 11]</H1
|
><DIV
|
><DIV
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><H2
|
><H2
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><A
|
><A
|
NAME="AEN13150">Functions Implemented</H2
|
NAME="AEN13150">Functions Implemented</H2
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>int sem_init(sem_t *sem, int pshared, unsigned int value);
|
>int sem_init(sem_t *sem, int pshared, unsigned int value);
|
int sem_destroy(sem_t *sem);
|
int sem_destroy(sem_t *sem);
|
int sem_wait(sem_t *sem);
|
int sem_wait(sem_t *sem);
|
int sem_trywait(sem_t *sem);
|
int sem_trywait(sem_t *sem);
|
int sem_post(sem_t *sem);
|
int sem_post(sem_t *sem);
|
int sem_getvalue(sem_t *sem, int *sval);
|
int sem_getvalue(sem_t *sem, int *sval);
|
int pthread_mutexattr_init( pthread_mutexattr_t *attr);
|
int pthread_mutexattr_init( pthread_mutexattr_t *attr);
|
int pthread_mutexattr_destroy( pthread_mutexattr_t *attr);
|
int pthread_mutexattr_destroy( pthread_mutexattr_t *attr);
|
int pthread_mutex_init(pthread_mutex_t *mutex,
|
int pthread_mutex_init(pthread_mutex_t *mutex,
|
const pthread_mutexattr_t *mutex_attr);
|
const pthread_mutexattr_t *mutex_attr);
|
int pthread_mutex_destroy(pthread_mutex_t *mutex);
|
int pthread_mutex_destroy(pthread_mutex_t *mutex);
|
int pthread_mutex_lock(pthread_mutex_t *mutex);
|
int pthread_mutex_lock(pthread_mutex_t *mutex);
|
int pthread_mutex_trylock(pthread_mutex_t *mutex);
|
int pthread_mutex_trylock(pthread_mutex_t *mutex);
|
int pthread_mutex_unlock(pthread_mutex_t *mutex);
|
int pthread_mutex_unlock(pthread_mutex_t *mutex);
|
int pthread_condattr_init(pthread_condattr_t *attr);
|
int pthread_condattr_init(pthread_condattr_t *attr);
|
int pthread_condattr_destroy(pthread_condattr_t *attr);
|
int pthread_condattr_destroy(pthread_condattr_t *attr);
|
int pthread_cond_init(pthread_cond_t *cond,
|
int pthread_cond_init(pthread_cond_t *cond,
|
const pthread_condattr_t *attr);
|
const pthread_condattr_t *attr);
|
int pthread_cond_destroy(pthread_cond_t *cond);
|
int pthread_cond_destroy(pthread_cond_t *cond);
|
int pthread_cond_signal(pthread_cond_t *cond);
|
int pthread_cond_signal(pthread_cond_t *cond);
|
int pthread_cond_broadcast(pthread_cond_t *cond);
|
int pthread_cond_broadcast(pthread_cond_t *cond);
|
int pthread_cond_wait(pthread_cond_t *cond,
|
int pthread_cond_wait(pthread_cond_t *cond,
|
pthread_mutex_t *mutex);
|
pthread_mutex_t *mutex);
|
int pthread_cond_timedwait(pthread_cond_t *cond,
|
int pthread_cond_timedwait(pthread_cond_t *cond,
|
pthread_mutex_t *mutex,
|
pthread_mutex_t *mutex,
|
const struct timespec *abstime);</PRE
|
const struct timespec *abstime);</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><H2
|
><H2
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><A
|
><A
|
NAME="AEN13153">Functions Omitted</H2
|
NAME="AEN13153">Functions Omitted</H2
|
><TABLE
|
><TABLE
|
BORDER="5"
|
BORDER="5"
|
BGCOLOR="#E0E0F0"
|
BGCOLOR="#E0E0F0"
|
WIDTH="70%"
|
WIDTH="70%"
|
><TR
|
><TR
|
><TD
|
><TD
|
><PRE
|
><PRE
|
CLASS="SCREEN"
|
CLASS="SCREEN"
|
>sem_t *sem_open(const char *name, int oflag, ...); // TBA
|
>sem_t *sem_open(const char *name, int oflag, ...); // TBA
|
int sem_close(sem_t *sem); // TBA
|
int sem_close(sem_t *sem); // TBA
|
int sem_unlink(const char *name); // TBA
|
int sem_unlink(const char *name); // TBA
|
int pthread_mutexattr_getpshared( const pthread_mutexattr_t *attr,
|
int pthread_mutexattr_getpshared( const pthread_mutexattr_t *attr,
|
int *pshared );
|
int *pshared );
|
int pthread_mutexattr_setpshared( const pthread_mutexattr_t *attr,
|
int pthread_mutexattr_setpshared( const pthread_mutexattr_t *attr,
|
int pshared );
|
int pshared );
|
int pthread_condattr_getpshared( const pthread_condattr_t *attr,
|
int pthread_condattr_getpshared( const pthread_condattr_t *attr,
|
int *pshared);
|
int *pshared);
|
int pthread_condattr_setpshared( const pthread_condattr_t *attr,
|
int pthread_condattr_setpshared( const pthread_condattr_t *attr,
|
int pshared);</PRE
|
int pshared);</PRE
|
></TD
|
></TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><H2
|
><H2
|
CLASS="SECT2"
|
CLASS="SECT2"
|
><A
|
><A
|
NAME="AEN13156">Notes</H2
|
NAME="AEN13156">Notes</H2
|
><P
|
><P
|
></P
|
></P
|
><UL
|
><UL
|
><LI
|
><LI
|
><P
|
><P
|
> The presence of semaphores is controlled by the
|
> The presence of semaphores is controlled by the
|
CYGPKG_POSIX_SEMAPHORES option. This in turn
|
CYGPKG_POSIX_SEMAPHORES option. This in turn
|
causes the _POSIX_SEMAPHORES feature test
|
causes the _POSIX_SEMAPHORES feature test
|
macro to be defined and the semaphore API to be made
|
macro to be defined and the semaphore API to be made
|
available.
|
available.
|
</P
|
</P
|
></LI
|
></LI
|
><LI
|
><LI
|
><P
|
><P
|
> The <SPAN
|
> The <SPAN
|
CLASS="strong"
|
CLASS="strong"
|
><B
|
><B
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>pshared</B
|
>pshared</B
|
></SPAN
|
></SPAN
|
> argument to
|
> argument to
|
<SPAN
|
<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>sem_init()</I
|
>sem_init()</I
|
></SPAN
|
></SPAN
|
> is not implemented,
|
> is not implemented,
|
its value is ignored.
|
its value is ignored.
|
</P
|
</P
|
></LI
|
></LI
|
><LI
|
><LI
|
><P
|
><P
|
> Functions <SPAN
|
> Functions <SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>sem_open()</I
|
>sem_open()</I
|
></SPAN
|
></SPAN
|
>,
|
>,
|
<SPAN
|
<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>sem_close()</I
|
>sem_close()</I
|
></SPAN
|
></SPAN
|
> and
|
> and
|
<SPAN
|
<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>sem_unlink()</I
|
>sem_unlink()</I
|
></SPAN
|
></SPAN
|
> are present but
|
> are present but
|
always return an error (ENOSYS).
|
always return an error (ENOSYS).
|
</P
|
</P
|
></LI
|
></LI
|
><LI
|
><LI
|
><P
|
><P
|
> The exact priority inversion protocols supported may be
|
> The exact priority inversion protocols supported may be
|
controlled with the
|
controlled with the
|
_POSIX_THREAD_PRIO_INHERIT and
|
_POSIX_THREAD_PRIO_INHERIT and
|
_POSIX_THREAD_PRIO_PROTECT
|
_POSIX_THREAD_PRIO_PROTECT
|
configuration options.
|
configuration options.
|
</P
|
</P
|
></LI
|
></LI
|
><LI
|
><LI
|
><P
|
><P
|
> {_POSIX_THREAD_PROCESS_SHARED} is
|
> {_POSIX_THREAD_PROCESS_SHARED} is
|
not defined, so the
|
not defined, so the
|
<SPAN
|
<SPAN
|
CLASS="strong"
|
CLASS="strong"
|
><B
|
><B
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>process-shared</B
|
>process-shared</B
|
></SPAN
|
></SPAN
|
> mutex
|
> mutex
|
and condition variable attributes are not supported, and
|
and condition variable attributes are not supported, and
|
neither are the functions
|
neither are the functions
|
<SPAN
|
<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>pthread_mutexattr_getpshared()</I
|
>pthread_mutexattr_getpshared()</I
|
></SPAN
|
></SPAN
|
>,
|
>,
|
<SPAN
|
<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>pthread_mutexattr_setpshared()</I
|
>pthread_mutexattr_setpshared()</I
|
></SPAN
|
></SPAN
|
>,
|
>,
|
<SPAN
|
<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>pthread_condattr_getpshared()</I
|
>pthread_condattr_getpshared()</I
|
></SPAN
|
></SPAN
|
> and
|
> and
|
<SPAN
|
<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>pthread_condattr_setpshared()</I
|
>pthread_condattr_setpshared()</I
|
></SPAN
|
></SPAN
|
>.
|
>.
|
</P
|
</P
|
></LI
|
></LI
|
><LI
|
><LI
|
><P
|
><P
|
> Condition variables do not become bound to a particular
|
> Condition variables do not become bound to a particular
|
mutex when
|
mutex when
|
<SPAN
|
<SPAN
|
CLASS="emphasis"
|
CLASS="emphasis"
|
><I
|
><I
|
CLASS="EMPHASIS"
|
CLASS="EMPHASIS"
|
>pthread_cond_wait()</I
|
>pthread_cond_wait()</I
|
></SPAN
|
></SPAN
|
> is
|
> is
|
called. Hence different threads may wait on a condition
|
called. Hence different threads may wait on a condition
|
variable with different mutexes. This is at variance with
|
variable with different mutexes. This is at variance with
|
the standard, which requires a condition variable to
|
the standard, which requires a condition variable to
|
become (dynamically) bound by the first waiter, and
|
become (dynamically) bound by the first waiter, and
|
unbound when the last finishes. However, this difference
|
unbound when the last finishes. However, this difference
|
is largely benign, and the cost of policing this feature
|
is largely benign, and the cost of policing this feature
|
is non-trivial.
|
is non-trivial.
|
</P
|
</P
|
></LI
|
></LI
|
></UL
|
></UL
|
></DIV
|
></DIV
|
></DIV
|
></DIV
|
><DIV
|
><DIV
|
CLASS="NAVFOOTER"
|
CLASS="NAVFOOTER"
|
><HR
|
><HR
|
ALIGN="LEFT"
|
ALIGN="LEFT"
|
WIDTH="100%"><TABLE
|
WIDTH="100%"><TABLE
|
SUMMARY="Footer navigation table"
|
SUMMARY="Footer navigation table"
|
WIDTH="100%"
|
WIDTH="100%"
|
BORDER="0"
|
BORDER="0"
|
CELLPADDING="0"
|
CELLPADDING="0"
|
CELLSPACING="0"
|
CELLSPACING="0"
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="posix-data-interchange-format.html"
|
HREF="posix-data-interchange-format.html"
|
ACCESSKEY="P"
|
ACCESSKEY="P"
|
>Prev</A
|
>Prev</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="ecos-ref.html"
|
HREF="ecos-ref.html"
|
ACCESSKEY="H"
|
ACCESSKEY="H"
|
>Home</A
|
>Home</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="posix-memory-management.html"
|
HREF="posix-memory-management.html"
|
ACCESSKEY="N"
|
ACCESSKEY="N"
|
>Next</A
|
>Next</A
|
></TD
|
></TD
|
></TR
|
></TR
|
><TR
|
><TR
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="left"
|
ALIGN="left"
|
VALIGN="top"
|
VALIGN="top"
|
>Data Interchange Format [POSIX Section 10]</TD
|
>Data Interchange Format [POSIX Section 10]</TD
|
><TD
|
><TD
|
WIDTH="34%"
|
WIDTH="34%"
|
ALIGN="center"
|
ALIGN="center"
|
VALIGN="top"
|
VALIGN="top"
|
><A
|
><A
|
HREF="posix-standard-support.html"
|
HREF="posix-standard-support.html"
|
ACCESSKEY="U"
|
ACCESSKEY="U"
|
>Up</A
|
>Up</A
|
></TD
|
></TD
|
><TD
|
><TD
|
WIDTH="33%"
|
WIDTH="33%"
|
ALIGN="right"
|
ALIGN="right"
|
VALIGN="top"
|
VALIGN="top"
|
>Memory Management [POSIX Section 12]</TD
|
>Memory Management [POSIX Section 12]</TD
|
></TR
|
></TR
|
></TABLE
|
></TABLE
|
></DIV
|
></DIV
|
></BODY
|
></BODY
|
></HTML
|
></HTML
|
|
|