Chapter 8Programming With Solaris Threads
This chapter compares the Application Programming Interface
(API) for Solaris and POSIX threads, and explains the Solaris features that
are not found in POSIX threads.
Comparing APIs for Solaris Threads and POSIX Threads
The Solaris threads API and the pthreads API are two solutions to the
same problem: building parallelism into application software. Although each
API is complete in itself, you can safely mix Solaris threads functions and
pthread functions in the same program.
The two APIs do not match exactly, however. Solaris threads supports
functions that are not found in pthreads, and pthreads includes functions
that are not supported in the Solaris interface. For those functions that do match, the associated arguments might not, although the information
content is effectively the same.
By combining the two APIs, you can use features not found in one to
enhance the other. Similarly, you can run applications using Solaris threads,
exclusively, with applications using pthreads, exclusively, on the same system.
Major API Differences
Solaris threads and pthreads are very similar in both API action and
syntax. The major differences are listed in Table 8-1.
Table 8-1 Unique Solaris Threads and pthreads Features
Solaris Threads
(libthread) | POSIX
Threads (libpthread) |
thr_ prefix
for threads function names; sema_ prefix for semaphore
function names | pthread_ prefix for pthreads function names; sem_
prefix for semaphore function names |
Ability to create "daemon"
threads | Cancellation
semantics |
Suspending and continuing a thread | Scheduling policies |
Function Comparison Table
The following table compares Solaris threads functions with pthreads
functions. Note that even when Solaris threads and pthreads functions appear
to be essentially the same, the arguments to the functions can differ.
When a comparable interface is not available either in pthreads or Solaris
threads, a hyphen `-' appears in the column. Entries in the pthreads column
that are followed by "POSIX 1003.4" or "POSIX.4" are
part of the POSIX Realtime standard specification and are not part of pthreads.
Table 8-2 Solaris Threads and POSIX pthreads Comparison
Solaris Threads
(libthread) | pthreads
(libpthread) |
thr_create() | pthread_create() |
thr_exit() | pthread_exit() |
thr_join() | pthread_join() |
thr_yield() | sched_yield() POSIX.4 |
thr_self() | pthread_self() |
thr_kill() | pthread_kill() |
thr_sigsetmask() | pthread_sigmask() |
thr_setprio() | pthread_setschedparam() |
thr_getprio() | pthread_getschedparam() |
thr_setconcurrency() | pthread_setconcurrency() |
thr_getconcurrency() | pthread_getconcurrency() |
thr_suspend() | - |
thr_continue() | - |
thr_keycreate() | pthread_key_create() |
- | pthread_key_delete() |
thr_setspecific() | pthread_setspecific() |
thr_getspecific() | pthread_getspecific() |
- | pthread_once() |
- | pthread_equal() |
- | pthread_cancel() |
- | pthread_testcancel() |
- | pthread_cleanup_push() |
- | pthread_cleanup_pop() |
- | pthread_setcanceltype() |
- | pthread_setcancelstate() |
mutex_lock() | pthread_mutex_lock() |
mutex_unlock() | pthread_mutex_unlock() |
mutex_trylock() | pthread_mutex_trylock() |
mutex_init() | pthread_mutex_init() |
mutex_destroy() | pthread_mutex_destroy()
|
cond_wait() | pthread_cond_wait() |
cond_timedwait() | pthread_cond_timedwait() |
cond_reltimedwait() | pthread_cond_reltimedwait_np() |
cond_signal() | pthread_cond_signal() |
cond_broadcast() | pthread_cond_broadcast() |
cond_init() | pthread_cond_init() |
cond_destroy() | pthread_cond_destroy() |
rwlock_init() | pthread_rwlock_init() |
rwlock_destroy() | pthread_rwlock_destroy() |
rw_rdlock() | pthread_rwlock_rdlock() |
rw_wrlock() | pthread_rwlock_wrlock() |
rw_unlock() | pthread_rwlock_unlock() |
rw_tryrdlock() | pthread_rwlock_tryrdlock() |
rw_trywrlock() | pthread_rwlock_trywrlock() |
- | pthread_rwlockattr_init() |
- | pthread_rwlockattr_destroy() |
- | pthread_rwlockattr_getpshared() |
- | pthread_rwlockattr_setpshared() |
sema_init() | sem_init() POSIX
1003.4 |
sema_destroy() | sem_destroy()
POSIX 1003.4 |
sema_wait() | sem_wait() POSIX
1003.4 |
sema_post() | sem_post() POSIX
1003.4 |
sema_trywait() | sem_trywait()
POSIX 1003.4 |
fork1() | fork() |
- | pthread_atfork() |
fork() (multiple
thread copy) | - |
- | pthread_mutexattr_init() |
- | pthread_mutexattr_destroy() |
type argument
in mutex_init() | pthread_mutexattr_setpshared() |
- | pthread_mutexattr_getpshared() |
- | pthread_mutex_attr_settype()
|
- | pthread_mutex_attr_gettype() |
- | pthread_condattr_init() |
- | pthread_condattr_destroy() |
type argument
in cond_init() | pthread_condattr_setpshared() |
- | pthread_condattr_getpshared() |
- | pthread_attr_init() |
- | pthread_attr_destroy() |
THR_BOUND flag in thr_create() | pthread_attr_setscope() |
- | pthread_attr_getscope() |
- | pthread_attr_setguardsize() |
- | pthread_attr_getguardsize() |
stack_size
argument in thr_create() | pthread_attr_setstacksize() |
- | pthread_attr_getstacksize() |
stack_addr
argument in thr_create() | pthread_attr_setstackaddr() |
- | pthread_attr_getstackaddr() |
THR_DETACH flag in thr_create() | pthread_attr_setdetachstate() |
- | pthread_attr_getdetachstate() |
- | pthread_attr_setschedparam() |
- | pthread_attr_getschedparam() |
- | pthread_attr_setinheritsched() |
- | pthread_attr_getinheritsched() |
- | pthread_attr_setsschedpolicy() |
- | pthread_attr_getschedpolicy() |
|