thread_wait Subroutine

Purpose

Suspends the thread until it receives a post or times out.

Library

Standard C library (libc.a)

Syntax

#include <sys/thread.h>

int thread_wait( timeout)
int  timeout;

Description

The thread_wait subroutine allows a thread to wait or block until another thread posts it with the thread_post or the thread_post_many subroutine or until the time limit specified by the timeout value expires. It returns immediately if there is a pending post for this thread or if a timeout value of 0 is specified.

If the event for which the thread is waiting and for which it will be posted will occur only in the future, the thread_wait subroutine may be called with a timeout value of 0 to clear any pending posts.

The thread_wait and the thread_post subroutine can be used by applications to implement a fast IPC mechanism between threads in different processes.

Parameters

Item Description
timeout Specifies the maximum length of time, in milliseconds, to wait for a posting. If the timeout parameter value is -1, the thread_wait subroutine does not return until a posting actually occurs. If the value of the timeout parameter is 0, the thread_wait subroutine does not wait for a post to occur but returns immediately, even if there are no pending posts. For a non-privileged user, the minimum timeout value is 10 msec and any value less than that is automatically increased to 10 msec.

Return Values

On successful completion, the thread_wait subroutine returns a value of 0. The thread_wait subroutine completes successfully if there was a pending post or if the calling thread was posted before the time limit specified by the timeout parameter expires.

A return value of THREAD_WAIT_TIMEDOUT indicates that the thread_wait subroutine timed out.

If unsuccessful, a value of -1 is returned and the global variable errno is set to indicate the error.

Error Codes

The thread_wait subroutine is unsuccessful when one of the following is true:
Item Description
EINTR This subroutine was terminated by receipt of a signal.
ENOMEM There is not enough memory to allocate a timer