下表对 Solaris 线程函数和 pthread 函数进行了比较。请注意,即使 Solaris 线程函数和 pthread 函数看上去完全相同,但是其参数可以不同。
如果某个进行比较的接口在 pthread 或 Solaris 线程中不可用,则会在相应的列中显示一个连字符 "-"。pthread 列中后跟 "POSIX.1b" 的各项属于 POSIX 实时标准规范,而不属于 pthread。
表 8–2 Solaris 线程和 POSIX pthread 的比较
Solaris 线程 |
pthread |
---|---|
thr_create() |
pthread_create() |
thr_exit() |
pthread_exit() |
thr_join() |
pthread_join() |
thr_yield() |
sched_yield() POSIX.1b |
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.1b |
sema_destroy() |
sem_destroy() POSIX.1b |
sema_wait() |
sem_wait() POSIX.1b |
sema_post() |
sem_post() POSIX.1b |
sema_trywait() |
sem_trywait() POSIX.1b |
fork1() |
fork() |
- |
pthread_atfork() |
forkall(),多线程副本 |
- |
- |
pthread_mutexattr_init() |
- |
pthread_mutexattr_destroy() |
mutex_init() 中的 type 参数 |
pthread_mutexattr_setpshared() |
- |
pthread_mutexattr_getpshared() |
- |
pthread_mutex_attr_settype() |
- |
pthread_mutex_attr_gettype() |
- |
pthread_condattr_init() |
- |
pthread_condattr_destroy() |
cond_init() 中的 type 参数 |
pthread_condattr_setpshared() |
- |
pthread_condattr_getpshared() |
- |
pthread_attr_init() |
- |
pthread_attr_destroy() |
thr_create() 中的 THR_BOUND 标志 |
pthread_attr_setscope() |
- |
pthread_attr_getscope() |
- |
pthread_attr_setguardsize() |
- |
pthread_attr_getguardsize() |
thr_create() 中的 stack_size 参数 |
pthread_attr_setstacksize() |
- |
pthread_attr_getstacksize() |
thr_create() 中的 stack_addr 参数 |
pthread_attr_setstack() |
- |
pthread_attr_getstack() |
thr_create() 中的 THR_DETACH 标志 |
pthread_attr_setdetachstate() |
- |
pthread_attr_getdetachstate() |
- |
pthread_attr_setschedparam() |
- |
pthread_attr_getschedparam() |
- |
pthread_attr_setinheritsched() |
- |
pthread_attr_getinheritsched() |
- |
pthread_attr_setsschedpolicy() |
- |
pthread_attr_getschedpolicy() |
要使用本章中介绍的用于 Solaris 9 和以前发行版的 Solaris 线程函数,必须使用 Solaris 线程库 -lthread 进行链接。
对于 Solaris 线程和 pthread 来说,即使函数名或参数可能会有所不同,但是操作实际上是相同的。此处仅提供了一个简单的示例,其中包括正确的头文件和函数原型。如果没有为 Solaris 线程函数提供返回值,请参见《man pages section 3: Basic Library Functions》中的相应页以获取函数的返回值。
有关 Solaris 相关函数的更多信息,请参见相关 pthread 文档中以类似方式命名的函数。
如果 Solaris 线程函数所提供的功能在 pthread 中不可用,则会提供这些函数的完整说明。