1threads(5)            Standards, Environments, and Macros           threads(5)
2
3
4

NAME

6       threads, pthreads - POSIX pthreads and Solaris threads concepts
7

SYNOPSIS

9   POSIX
10       cc -mt [ flag... ] file... [ -lrt library... ]
11
12
13       #include <pthread.h>
14
15
16   Solaris
17       cc -mt [ flag... ] file... [ library... ]
18
19
20       #include <sched.h>
21
22
23       #include <thread.h>
24
25

DESCRIPTION

27       POSIX  and  Solaris  threads  each have their own implementation within
28       libc(3LIB). Both implementations are interoperable, their functionality
29       similar,  and  can  be  used  within  the  same application. Only POSIX
30       threads are guaranteed to be fully portable  to  other  POSIX-compliant
31       environments.  POSIX  and  Solaris  threads  require  different source,
32       include files and linking libraries. See SYNOPSIS.
33
34   Similarities
35       Most of the POSIX and Solaris  threading  functions  have  counterparts
36       with  each other. POSIX function names, with the exception of the sema‐
37       phore names, have a "pthread" prefix. Function names for similar  POSIX
38       and  Solaris  functions  have similar endings. Typically, similar POSIX
39       and Solaris functions have the same number and use of arguments.
40
41   Differences
42       POSIX pthreads and Solaris threads differ in the following ways:
43
44           o      POSIX threads are more portable.
45
46           o      POSIX threads establish  characteristics   for  each  thread
47                  according to configurable attribute objects.
48
49           o      POSIX pthreads implement thread cancellation.
50
51           o      POSIX pthreads enforce scheduling algorithms.
52
53           o      POSIX  pthreads  allow  for  clean-up  handlers  for fork(2)
54                  calls.
55
56           o      Solaris threads can be suspended and continued.
57
58           o      Solaris threads implement daemon threads, for  whose  demise
59                  the process does not wait.
60

FUNCTION COMPARISON

62       The  following  table  compares  the POSIX pthreads and Solaris threads
63       functions. When a comparable interface is not available either in POSIX
64       pthreads  or Solaris threads, a hyphen (-) appears in the column.
65
66   Functions Related to Creation
67       POSIX                            Solaris
68
69       pthread_create()                 thr_create()
70       pthread_attr_init()              -
71       pthread_attr_setdetachstate()    -
72       pthread_attr_getdetachstate()    -
73       pthread_attr_setinheritsched()   -
74       pthread_attr_getinheritsched()   -
75       pthread_attr_setschedparam()     -
76       pthread_attr_getschedparam()     -
77       pthread_attr_setschedpolicy()    -
78       pthread_attr_getschedpolicy()    -
79       pthread_attr_setscope()          -
80       pthread_attr_getscope()          -
81       pthread_attr_setstackaddr()      -
82       pthread_attr_getstackaddr()      -
83       pthread_attr_setstacksize()      -
84       pthread_attr_getstacksize()      -
85       pthread_attr_getguardsize()      -
86       pthread_attr_setguardsize()      -
87       pthread_attr_destroy()           -
88       -                                thr_min_stack()
89
90
91   Functions Related to Exit
92       POSIX                         Solaris
93       pthread_exit()                thr_exit()
94       pthread_join()                thr_join()
95       pthread_detach()              -
96
97
98   Functions Related to Thread Specific Data
99       POSIX                         Solaris
100       pthread_key_create()          thr_keycreate()
101       pthread_setspecific()         thr_setspecific()
102       pthread_getspecific()         thr_getspecific()
103       pthread_key_delete()          -
104
105
106   Functions Related to Signals
107       POSIX                         Solaris
108       pthread_sigmask()             thr_sigsetmask()
109       pthread_kill()                thr_kill()
110
111
112   Functions Related to IDs
113       POSIX                         Solaris
114       pthread_self()                thr_self()
115       pthread_equal()               -
116       -                             thr_main()
117
118
119   Functions Related to Scheduling
120       POSIX                         Solaris
121       -                             thr_yield()
122       -                             thr_suspend()
123       -                             thr_continue()
124       pthread_setconcurrency()      thr_setconcurrency()
125       pthread_getconcurrency()      thr_getconcurrency()
126       pthread_setschedparam()       thr_setprio()
127       pthread_setschedprio()        thr_setprio()
128       pthread_getschedparam()       thr_getprio()
129
130
131   Functions Related to Cancellation
132       POSIX                         Solaris
133       pthread_cancel()              -
134       pthread_setcancelstate()      -
135       pthread_setcanceltype()       -
136
137       pthread_testcancel()          -
138       pthread_cleanup_pop()         -
139       pthread_cleanup_push()        -
140
141
142   Functions Related to Mutexes
143       POSIX                                    Solaris
144       pthread_mutex_init()                     mutex_init()
145       pthread_mutexattr_init()                 -
146       pthread_mutexattr_setpshared()           -
147       pthread_mutexattr_getpshared()           -
148       pthread_mutexattr_setprotocol()          -
149       pthread_mutexattr_getprotocol()          -
150       pthread_mutexattr_setprioceiling()       -
151       pthread_mutexattr_getprioceiling()       -
152       pthread_mutexattr_settype()              -
153       pthread_mutexattr_gettype()              -
154       pthread_mutexattr_setrobust()            -
155       pthread_mutexattr_getrobust()            -
156       pthread_mutexattr_destroy()              -
157       pthread_mutex_setprioceiling()           -
158       pthread_mutex_getprioceiling()           -
159       pthread_mutex_lock()                     mutex_lock()
160       pthread_mutex_trylock()                  mutex_trylock()
161       pthread_mutex_unlock()                   mutex_unlock()
162       pthread_mutex_destroy()                  mutex_destroy()
163
164
165   Functions Related to Condition Variables
166       POSIX                           Solaris
167       pthread_cond_init()             cond_init()
168       pthread_condattr_init()         -
169       pthread_condattr_setpshared()   -
170       pthread_condattr_getpshared()   -
171       pthread_condattr_destroy()      -
172       pthread_cond_wait()             cond_wait()
173       pthread_cond_timedwait()        cond_timedwait()
174       pthread_cond_signal()           cond_signal()
175       pthread_cond_broadcast()        cond_broadcast()
176       pthread_cond_destroy()          cond_destroy()
177
178
179   Functions Related to Reader/Writer Locking
180       POSIX                             Solaris
181       pthread_rwlock_init()             rwlock_init()
182       pthread_rwlock_rdlock()           rw_rdlock()
183       pthread_rwlock_tryrdlock()        rw_tryrdlock()
184       pthread_rwlock_wrlock()           rw_wrlock()
185       pthread_rwlock_trywrlock()        rw_trywrlock()
186       pthread_rwlock_unlock()           rw_unlock()
187       pthread_rwlock_destroy()          rwlock_destroy()
188       pthread_rwlockattr_init()         -
189       pthread_rwlockattr_destroy()      -
190       pthread_rwlockattr_getpshared()   -
191       pthread_rwlockattr_setpshared()   -
192
193
194   Functions Related to Semaphores
195       POSIX                         Solaris
196       sem_init()                    sema_init()
197       sem_open()                    -
198       sem_close()                   -
199       sem_wait()                    sema_wait()
200       sem_trywait()                 sema_trywait()
201       sem_post()                    sema_post()
202       sem_getvalue()                -
203       sem_unlink()                  -
204
205       sem_destroy()                 sema_destroy()
206
207
208   Functions Related to fork() Clean Up
209       POSIX                         Solaris
210       pthread_atfork()              -
211
212
213   Functions Related to Limits
214       POSIX                         Solaris
215       pthread_once()                -
216
217
218   Functions Related to Debugging
219       POSIX                         Solaris
220       -                             thr_stksegment()
221
222

LOCKING

224   Synchronization
225       Multithreaded  behavior  is asynchronous, and therefore,  optimized for
226       concurrent and parallel processing. As threads, always from within  the
227       same  process and  sometimes from multiple processes, share global data
228       with each other, they are not guaranteed exclusive access to the shared
229       data at any point in time. Securing mutually exclusive access to shared
230       data requires   synchronization  among  the  threads.  Both  POSIX  and
231       Solaris  implement  four synchronization mechanisms: mutexes, condition
232       variables, reader/writer locking  (optimized frequent-read  occasional-
233       write mutex), and semaphores.
234
235
236       Synchronizing   multiple  threads  diminishes  their  concurrency.  The
237       coarser the grain of synchronization, that is, the larger the block  of
238       code that is locked, the lesser the concurrency.
239
240   MT fork()
241       If a threads program calls fork(2), it implicitly calls fork1(2), which
242       replicates only the calling thread. Should  there  be  any  outstanding
243       mutexes   throughout   the   process,   the   application  should  call
244       pthread_atfork(3C) to wait for and acquire those mutexes prior to call‐
245       ing fork().
246

SCHEDULING

248   POSIX Threads
249       Solaris supports the following three POSIX scheduling policies:
250
251       SCHED_OTHER    Traditional  Timesharing  scheduling policy. It is based
252                      on the timesharing (TS) scheduling class.
253
254
255       SCHED_FIFO     First-In-First-Out scheduling policy. Threads  scheduled
256                      to  this  policy, if not preempted by a higher priority,
257                      will proceed until completion. Such threads are in real-
258                      time  (RT)  scheduling  class.  The calling process must
259                      have a effective user ID of 0.
260
261
262       SCHED_RR       Round-Robin scheduling policy. Threads scheduled to this
263                      policy, if not preempted by a higher priority, will exe‐
264                      cute for a time period determined by  the  system.  Such
265                      threads  are  in real-time (RT) scheduling class and the
266                      calling process must have a effective user ID of 0.
267
268
269
270       In addition to the POSIX-specified scheduling policies  above,  Solaris
271       also supports these scheduling policies:
272
273       SCHED_IA     Threads  are scheduled according to the Inter-Active Class
274                    (IA) policy as described in priocntl(2).
275
276
277       SCHED_FSS    Threads are scheduled according to  the  Fair-Share  Class
278                    (FSS) policy as described in priocntl(2).
279
280
281       SCHED_FX     Threads  are  scheduled  according  to  the Fixed-Priority
282                    Class (FX) policy as described in priocntl(2).
283
284
285   Solaris Threads
286       Only scheduling policy supported is SCHED_OTHER, which is  timesharing,
287       based on the TS scheduling class.
288

ERRORS

290       In  a  multithreaded  application,  EINTR can be returned from blocking
291       system calls when another thread calls  forkall(2).
292

USAGE

294   -mt compiler option
295       The -mt compiler option compiles and links for multithreaded  code.  It
296       compiles source files with −D_REENTRANT and augments the set of support
297       libraries properly.
298

ATTRIBUTES

300       See attributes(5) for descriptions of the following attributes:
301
302
303
304
305       ┌─────────────────────────────┬─────────────────────────────┐
306       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
307       ├─────────────────────────────┼─────────────────────────────┤
308       │MT-Level                     │MT-Safe, Fork 1-Safe         │
309       └─────────────────────────────┴─────────────────────────────┘
310

SEE ALSO

312       crle(1),   fork(2),   priocntl(2),    libpthread(3LIB),    librt(3LIB),
313       libthread(3LIB), pthread_atfork(3C), pthread_create(3C), attributes(5),
314       standards(5)
315
316
317       Linker and Libraries Guide
318
319
320
321SunOS 5.11                        11 Nov 2008                       threads(5)
Impressum