この節では、Solaris スレッドに固有の次の関数について説明します。 スレッドの実行を中断する関数と、中断したスレッドを再開する関数です。
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 が存在しません。
thr_continue(3C) は、停止しているスレッドの実行を再開します。再開したスレッドに対して再度 thr_continue() を発行しても効果はありません。
#include <thread.h> int thr_continue(thread_t tid);
停止しているスレッドは、シグナルでは呼び起こされません。送られたシグナルは、そのスレッドが thr_continue() で再開されるまで保留されます。
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_continue(tid); /* using pthreads ID variable with a cast */ ret = thr_continue((thread_t) ptid)
thr_continue()は、正常終了時に 0 を返します。それ以外の戻り値は、エラーが発生したことを示します。以下の条件が検出されると、thr_continue() は失敗し、対応する値を戻します。
ESRCH
説明:現在のプロセスに tid が存在しません。