thr_suspend(3C) は、target_thread で指定されたスレッドの実行をただちに停止します。thr_suspend() が正常終了した時点で、指定のスレッドは実行状態ではありません。
thr_suspend() が目的のスレッドを停止するとき、そのスレッドが保持しているロックについては考慮されません。したがって、thr_suspend() は慎重に使用する必要があります。一時停止したスレッドに保持されているロックを必要とする関数が呼び出されると、デッドロックが発生します。
#include <thread.h> int thr_suspend(thread_t tid);
停止しているスレッドに対して再度 thr_suspend() を発行しても効果はありません。停止しているスレッドをシグナルで呼び起こすことはできません。スレッドが実行を再開するまでシグナルは保留状態のままです。
次の例では、pthread で定義されている pthread_t
tid と Solaris スレッドの thread_t
tid が同じです。tid 値は、代入によっても型変換によっても使用できます。
thread_t tid; /* tid from thr_create() */ /* pthreads equivalent of 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()は、正常終了時に 0 を返します。それ以外の戻り値は、エラーが発生したことを示します。以下の条件が検出されると、thr_suspend() は失敗し、対応する値を返します。
ESRCH
説明:現在のプロセスに tid が存在しません。