threads, pthreads - POSIX pthreads and Solaris threads concepts
cc -mt [ flag... ] file... [ -lrt library... ]
#include <pthread.h>
cc -mt [ flag... ] file... [ library... ]
#include <sched.h>
#include <thread.h>
POSIX and Solaris threads each have their own implementation within libc(3LIB). Both implementations are interoperable, their functionality similar, and can be used within the same application. Only POSIX threads are guaranteed to be fully portable to other POSIX-compliant environments. POSIX and Solaris threads require different source, include files and linking libraries. See SYNOPSIS.
Most of the POSIX and Solaris threading functions have counterparts with each other. POSIX function names, with the exception of the semaphore names, have a "pthread" prefix. Function names for similar POSIX and Solaris functions have similar endings. Typically, similar POSIX and Solaris functions have the same number and use of arguments.
POSIX pthreads and Solaris threads differ in the following ways:
The following table compares the POSIX pthreads and Solaris threads functions. When a comparable interface is not available either in POSIX pthreads or Solaris threads, a hyphen (-) appears in the column.
POSIX | Solaris |
pthread_create() | thr_create() |
pthread_attr_init() | |
pthread_attr_setdetachstate() | |
pthread_attr_getdetachstate() | |
pthread_attr_setinheritsched() | |
pthread_attr_getinheritsched() | |
pthread_attr_setschedparam() | |
pthread_attr_getschedparam() | |
pthread_attr_setschedpolicy() | |
pthread_attr_getschedpolicy() | |
pthread_attr_setscope() | |
pthread_attr_getscope() | |
pthread_attr_setstackaddr() | |
pthread_attr_getstackaddr() | |
pthread_attr_setstacksize() | |
pthread_attr_getstacksize() | |
pthread_attr_getguardsize() | |
pthread_attr_setguardsize() | |
pthread_attr_destroy() | |
- |
POSIX | Solaris |
pthread_exit() | thr_exit() |
pthread_join() | |
pthread_detach() |
POSIX | Solaris |
pthread_key_create() | thr_keycreate() |
pthread_setspecific() | |
pthread_getspecific() | |
pthread_key_delete() |
POSIX | Solaris |
pthread_sigmask() | thr_sigsetmask() |
pthread_kill() |
POSIX | Solaris |
pthread_self() | thr_self() |
pthread_equal() | |
- |
POSIX | Solaris |
- | thr_yield() |
- | |
- | |
pthread_setconcurrency() | |
pthread_getconcurrency() | |
pthread_setschedparam() | |
pthread_setschedprio() | |
pthread_getschedparam() |
POSIX | Solaris |
pthread_cancel() | - |
pthread_setcancelstate() | |
pthread_setcanceltype() | |
pthread_testcancel() | |
pthread_cleanup_pop() | |
pthread_cleanup_push() |
POSIX | Solaris |
pthread_mutex_init() | mutex_init() |
pthread_mutexattr_init() | |
pthread_mutexattr_setpshared() | |
pthread_mutexattr_getpshared() | |
pthread_mutexattr_setprotocol() | |
pthread_mutexattr_getprotocol() | |
pthread_mutexattr_setprioceiling() | |
pthread_mutexattr_getprioceiling() | |
pthread_mutexattr_settype() | |
pthread_mutexattr_gettype() | |
pthread_mutexattr_setrobust() | |
pthread_mutexattr_getrobust() | |
pthread_mutexattr_destroy() | |
pthread_mutex_setprioceiling() | |
pthread_mutex_getprioceiling() | |
pthread_mutex_lock() | |
pthread_mutex_trylock() | |
pthread_mutex_unlock() | |
pthread_mutex_destroy() |
POSIX | Solaris |
pthread_cond_init() | cond_init() |
pthread_condattr_init() | |
pthread_condattr_setpshared() | |
pthread_condattr_getpshared() | |
pthread_condattr_destroy() | |
pthread_cond_wait() | |
pthread_cond_timedwait() | |
pthread_cond_signal() | |
pthread_cond_broadcast() | |
pthread_cond_destroy() |
POSIX | Solaris |
pthread_rwlock_init() | rwlock_init() |
pthread_rwlock_rdlock() | |
pthread_rwlock_tryrdlock() | |
pthread_rwlock_wrlock() | |
pthread_rwlock_trywrlock() | |
pthread_rwlock_unlock() | |
pthread_rwlock_destroy() | |
pthread_rwlockattr_init() | |
pthread_rwlockattr_destroy() | |
pthread_rwlockattr_getpshared() | |
pthread_rwlockattr_setpshared() |
POSIX | Solaris |
sem_init() | sema_init() |
sem_open() | |
sem_close() | |
sem_wait() | |
sem_trywait() | |
sem_post() | |
sem_getvalue() | |
sem_unlink() | |
sem_destroy() |
POSIX | Solaris |
pthread_atfork() | - |
POSIX | Solaris |
pthread_once() | - |
POSIX | Solaris |
- | thr_stksegment() |
Multithreaded behavior is asynchronous, and therefore, optimized for concurrent and parallel processing. As threads, always from within the same process and sometimes from multiple processes, share global data with each other, they are not guaranteed exclusive access to the shared data at any point in time. Securing mutually exclusive access to shared data requires synchronization among the threads. Both POSIX and Solaris implement four synchronization mechanisms: mutexes, condition variables, reader/writer locking (optimized frequent-read occasional-write mutex), and semaphores.
Synchronizing multiple threads diminishes their concurrency. The coarser the grain of synchronization, that is, the larger the block of code that is locked, the lesser the concurrency.
If a threads program calls fork(2), it implicitly calls fork1(2), which replicates only the calling thread. Should there be any outstanding mutexes throughout the process, the application should call pthread_atfork(3C) to wait for and acquire those mutexes prior to calling fork().
Solaris supports the following three POSIX scheduling policies:
SCHED_OTHER
SCHED_FIFO
SCHED_RR
In addition to the POSIX-specified scheduling policies above, Solaris also supports these scheduling policies:
SCHED_IA
SCHED_FSS
SCHED_FX
Only scheduling policy supported is SCHED_OTHER, which is timesharing, based on the TS scheduling class.
In a multithreaded application, EINTR can be returned from blocking system calls when another thread calls forkall(2).
The -mt compiler option compiles and links for multithreaded code. It compiles source files with -D_REENTRANT and augments the set of support libraries properly.
See attributes(5) for descriptions of the following attributes:
|
crle(1), fork(2), priocntl(2), libpthread(3LIB), librt(3LIB), libthread(3LIB), pthread_atfork(3C), pthread_create(3C), attributes(5), standards(5)
Linker and Libraries Guide
Закладки на сайте Проследить за страницей |
Created 1996-2024 by Maxim Chirkov Добавить, Поддержать, Вебмастеру |