Go to main content

Multithreaded Programming Guide

Exit Print View

Updated: March 2019
 
 

Unique Oracle Solaris Threads Functions

This section describes unique Oracle Solaris threads functions: suspending thread execution and continuing a suspended thread.

Suspending Thread Execution

thr_suspend(3C) immediately suspends the execution of the thread specified by target_thread. On successful return from thr_suspend(), the suspended thread is no longer executing.

Because thr_suspend() suspends the target thread with no regard to the locks that the thread might be holding, you must use thr_suspend() with extreme care. If the suspending thread calls a function that requires a lock held by the suspended target thread, deadlock will result.

thr_suspend() Syntax

#include <thread.h>

int thr_suspend(thread_t tid);

After a thread is suspended, subsequent calls to thr_suspend() have no effect. Signals cannot awaken the suspended thread. The signals remain pending until the thread resumes execution.

In the following synopsis, pthread_t tid as defined in pthreads is the same as thread_t tid in Oracle Solaris threads. tid values can be used interchangeably either by assignment or through the use of casts.

thread_t tid; /* tid from thr_create() */

/* pthreads equivalent of Oracle Solaris tid from thread created */
/* with pthread_create() */
pthread_t ptid; 

int ret;

ret = thr_suspend(tid);

/* using pthreads ID variable with a cast */
ret = thr_suspend((thread_t) ptid); 

thr_suspend() Return Values

thr_suspend() returns zero after completing successfully. Any other return value indicates that an error occurred. When the following condition occurs, thr_suspend() fails and returns the corresponding value.

ESRCH

Description: tid cannot be found in the current process.

Continuing a Suspended Thread

thr_continue(3C) resumes the execution of a suspended thread. Once a suspended thread is continued, subsequent calls to thr_continue() have no effect.

thr_continue() Syntax

#include <thread.h>

int thr_continue(thread_t tid);

A suspended thread is not awakened by a signal. The signal remains pending until the execution of the thread is resumed by thr_continue().

pthread_t tid as defined in pthreads is the same as thread_t tid in Oracle Solaris threads. tid values can be used interchangeably either by assignment or through the use of casts.

thread_t tid; /* tid from thr_create()*/

/* pthreads equivalent of Oracle Solaris tid from thread created */
/* with pthread_create()*/
pthread_t ptid;

int ret;

ret = thr_continue(tid);

/* using pthreads ID variable with a cast */
ret = thr_continue((thread_t) ptid)

thr_continue() Return Values

thr_continue() returns zero after completing successfully. Any other return value indicates that an error occurred. When the following condition occurs, thr_continue() fails and returns the corresponding value.

ESRCH

Description: tid cannot be found in the current process.