pthread_suspend_np, pthread_unsuspend_np and pthread_continue_np Subroutine

Purpose

Suspends and resume execution of the pthread specified by thread.

Library

Threads Library (libpthreads.a)

Syntax

#include <pthread.h>

pthread_t thread;
int pthread_suspend_np(thread)
int pthread_unsuspend_np (thread);
int pthread_continue_np(thread);

Description

The pthread_suspend_np subroutine immediately suspends the execution of the pthread specified by thread. On successful return from pthread_suspend_np, the suspended pthread is no longer executing. If pthread_suspend_np is called for a pthread that is already suspended, the pthread is unchanged and pthread_suspend_np returns successful.

Deadlock can occur if pthread_suspend_np is used with the following pthread functions.

pthread_getrusage_np
pthread_cancel
pthread_detach
pthread_join
pthread_getunique_np
pthread_join_np
pthread_setschedparam
pthread_getschedparam
pthread_kill

To prevent deadlock, PTHREAD_SUSPENDIBLE=ON should be set.

The pthread_unsuspend_np routine decrements the suspend count and once the count is zero, the routine resumes the execution of a suspended pthread. If pthread_unsuspend_np is called for a pthread that is not suspended, the pthread is unchanged and pthread_unsuspend_np returns successful.

The pthread_continue_np routine clears the suspend count and resumes the execution of a suspended pthread. If pthread_continue_np is called for a pthread that is not suspended, the pthread is unchanged and pthread_continue_np returns successful.

A suspended pthread will not be awakened by a signal. The signal stays pending until the execution of pthread is resumed by pthread_continue_np.

Note: Using pthread_suspend_np should only be used by advanced users because improper use of this subcommand can lead to application deadlock or the target thread may be suspended holding application locks.

Parameters

Item Description
thread Specifies the target thread.

Return Values

Zero is returned when successful. A nonzero value indicates an error.

Error Codes

If any of the following conditions occur, pthread_suspend_np, pthread_unsuspend_np and pthread_continue_np fail and return the corresponding value:

Item Description
ESRCH The target thread specified by thread attribute cannot be found in the current process.