[Previous] [Contents] [Next]

ThreadJoin(), ThreadJoin_r()

Block until a thread terminates

Synopsis:

#include <sys/neutrino.h>

int ThreadJoin( int tid,
                void** status );


int ThreadJoin_r( int tid,
                  void** status );

Library:

libc

Description:

The ThreadJoin() and ThreadJoin_r() functions are identical except in the way they indicate errors. See the Returns section for details.

These kernel calls block until the thread specified by tid terminates. If status isn't NULL it saves the thread's exit status into the area pointed to by status. If the thread tid has already terminated, then ThreadJoin() immediately returns with success and the status if requested.

When ThreadJoin() returns successfully, the target thread has been successfully terminated. Until this point the thread ID tid won't be reused and a small kernel resource will be retained (a thread object).

You can't join a thread which is detached (see ThreadCreate() and ThreadDetach()).

The target thread must be joinable. Multiple pthread_join(), pthread_timedjoin(), ThreadJoin(), and ThreadJoin_r() calls on the same target thread aren't allowed.

Blocking states

STATE_JOIN
The calling thread blocks waiting for the indicated thread to exit.

Returns:

The only difference between these functions is the way they indicate errors:

ThreadJoin()
If an error occurs, -1 is returned and errno is set. Any other value returned indicates success.
ThreadJoin_r()
EOK is returned on success. This function does NOT set errno. If an error occurs, any value in the Errors section may be returned.

Errors:

EBUSY
Attempt to join a thread which has been joined by another thread.
EDEADLK
Attempt to join to yourself.
EFAULT
A fault occurred when the kernel tried to access status.
EINTR
The call was interrupted by a signal.
EINVAL
Attempt to join a thread which is detached (see ThreadDetach()).
ESRCH
The thread indicated by tid doesn't exist.
ETIMEDOUT
A kernel timeout unblocked the call. See TimerTimeout().

Classification:

QNX 6

Safety:
Cancellation point Yes
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

ThreadDetach()


[Previous] [Contents] [Next]