Yield Thread Execution
thr_yield(3THR)
thr_yield(3THR) causes the current thread to yield its execution in favor of another thread with the same or greater priority; otherwise it has no effect. There is no guarantee that a thread calling thr_yield() will do so.
#include <thread.h> void thr_yield(void); |
Send a Signal to a Thread
thr_kill(3THR)
thr_kill(3THR) sends a signal to a thread. (For POSIX threads, see "pthread_kill(3THR)".)
#include <thread.h> #include <signal.h> int thr_kill(thread_t target_thread, int sig); |
Access the Signal Mask of the Calling Thread
thr_sigsetmask(3THR)
Use thr_sigsetmask(3THR) to change or examine the signal mask of the calling thread.
#include <thread.h> #include <signal.h> int thr_sigsetmask(int how, const sigset_t *set, sigset_t *oset); |
Terminate a Thread
thr_exit(3THR)
Use thr_exit(3THR) to terminate a thread. (For POSIX threads, see "pthread_exit(3THR)".)
#include <thread.h> void thr_exit(void *status); |
Wait for Thread Termination
thr_join(3THR)
Use thr_join(3THR) to wait for a thread to terminate. (For POSIX threads, see "pthread_join(3THR)".)
#include <thread.h> int thr_join(thread_t tid, thread_t *departedid, void **status); |
Join specific
#include <thread.h> thread_t tid; thread_t departedid; int ret; void *status; /* waiting to join thread "tid" with status */ ret = thr_join(tid, &departedid, &status); /* waiting to join thread "tid" without status */ ret = thr_join(tid, &departedid, NULL); /* waiting to join thread "tid" without return id and status */ ret = thr_join(tid, NULL, NULL); |
When the tid is (thread_t)0, then thread_join() waits for any undetached thread in the process to terminate. In other words, when no thread identifier is specified, any undetached thread that exits causes thread_join() to return.
Join any
#include <thread.h> thread_t tid; thread_t departedid; int ret; void *status; /* waiting to join any non-detached thread with status */ ret = thr_join(0, &departedid, &status); |
By indicating 0 as the thread id in the Solaris thr_join(), a join will take place when any non detached thread in the process exits. The departedid will indicate the thread ID of the exiting thread.
Create a Thread-Specific Data Key
Except for the function names and arguments, thread specific data is the same for Solaris as it is for POSIX. The synopses for the Solaris functions are given in this section.
thr_keycreate(3THR)
thr_keycreate(3THR) allocates a key that is used to identify thread-specific data in a process. (For POSIX threads, see "pthread_key_create(3THR)".)
#include <thread.h> int thr_keycreate(thread_key_t *keyp, void (*destructor) (void *value)); |
Set Thread-Specific Data
thr_setspecific(3THR)
thr_setspecific(3THR) binds value to the thread-specific data key, key, for the calling thread. (For POSIX threads, see "pthread_setspecific(3THR)".)
#include <thread.h> int thr_setspecific(thread_key_t key, void *value); |
Get Thread-Specific Data
thr_getspecific(3THR)
thr_getspecific(3THR) stores the current value bound to key for the calling thread into the location pointed to by valuep. (For POSIX threads, see "pthread_getspecific(3THR)".)
#include <thread.h> int thr_getspecific(thread_key_t key, void **valuep); |
Set the Thread Priority
In Solaris threads, if a thread is to be created with a priority other than that of its parent's, it is created in SUSPEND mode. While suspended, the threads priority is modified using the thr_setprio(3THR) function call; then it is continued.
A higher priority thread will receive precedence by libthread over lower priority threads with respect to synchronization object contention.
thr_setprio(3THR)
thr_setprio(3THR) changes the priority of the thread, specified by tid, within the current process to the priority specified by newprio. (For POSIX threads, see "pthread_setschedparam(3THR)".)
#include <thread.h> int thr_setprio(thread_t tid, int newprio) |
By default, threads are scheduled based on fixed priorities that range from zero, the least significant, to 127 the most significant.
thread_t tid; int ret; int newprio = 20; /* suspended thread creation */ ret = thr_create(NULL, NULL, func, arg, THR_SUSPENDED, &tid); /* set the new priority of suspended child thread */ ret = thr_setprio(tid, newprio); /* suspended child thread starts executing with new priority */ ret = thr_continue(tid); |