Hallo, dies ist ein Test.
PWD: /www/data-lst1/unixsoft/unixsoft/kaempfer/.public_html
Running in File Mode
Relative path: ./../../../../../../sbin/../man/man7/threads.7
Real path: /usr/share/man/man7/threads.7
Zurück
'\" te .\" Copyright (c) 2008, 2023, Oracle and/or its affiliates. .TH threads 7 "12 Sep 2023" "Oracle Solaris 11.4" "Standards, Environments, Macros, Character Sets, and miscellany" .SH NAME threads, pthreads \- POSIX pthreads and Solaris threads concepts .SH SYNOPSIS .SS "POSIX" .LP .nf #include <pthread.h> .fi .SS "Solaris" .LP .nf #include <sched.h> .fi .LP .nf #include <thread.h> .fi .SH DESCRIPTION .sp .LP POSIX and Solaris threads each have their own implementation within \fBlibc\fR(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 code and include files. See \fBSYNOPSIS\fR. .SS "Similarities" .sp .LP 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 "\fBpthread\fR" 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. .SS "Differences" .sp .LP POSIX pthreads and Solaris threads differ in the following ways: .RS +4 .TP .ie t \(bu .el o POSIX threads are more portable. .RE .RS +4 .TP .ie t \(bu .el o POSIX threads have had more features added and may be extended to support newer abilities over time. Solaris threads are maintained for backwards compatibility, and do not receive such enhancements. .RE .RS +4 .TP .ie t \(bu .el o POSIX threads establish characteristics for each thread according to configurable attribute objects. .RE .RS +4 .TP .ie t \(bu .el o POSIX pthreads implement thread cancellation. .RE .RS +4 .TP .ie t \(bu .el o POSIX pthreads enforce scheduling algorithms. .RE .RS +4 .TP .ie t \(bu .el o POSIX pthreads allow for clean-up handlers for \fBfork\fR(2) calls. .RE .RS +4 .TP .ie t \(bu .el o Solaris threads can be suspended and continued. .RE .RS +4 .TP .ie t \(bu .el o Solaris threads implement daemon threads, for whose demise the process does not wait. .RE .SH FUNCTION COMPARISON .sp .LP 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 (\fB-\fR) appears in the column. .SS "Functions Related to Creation" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_create()\fR \fBthr_create()\fR \fBpthread_attr_init()\fR \fB-\fR \fBpthread_attr_setdetachstate()\fR \fB-\fR \fBpthread_attr_getdetachstate()\fR \fB-\fR \fBpthread_attr_setinheritsched()\fR \fB-\fR \fBpthread_attr_getinheritsched()\fR \fB-\fR \fBpthread_attr_setschedparam()\fR \fB-\fR \fBpthread_attr_getschedparam()\fR \fB-\fR \fBpthread_attr_setschedpolicy()\fR \fB-\fR \fBpthread_attr_getschedpolicy()\fR \fB-\fR \fBpthread_attr_setscope()\fR \fB-\fR \fBpthread_attr_getscope()\fR \fB-\fR \fBpthread_attr_setstackaddr()\fR \fB-\fR \fBpthread_attr_getstackaddr()\fR \fB-\fR \fBpthread_attr_setstacksize()\fR \fB-\fR \fBpthread_attr_getstacksize()\fR \fB-\fR \fBpthread_attr_getguardsize()\fR \fB-\fR \fBpthread_attr_setguardsize()\fR \fB-\fR \fBpthread_attr_destroy()\fR \fB-\fR \fBpthread_getattr_np()\fR \fB-\fR \fB-\fR \fBthr_min_stack()\fR .TE .sp .SS "Functions Related to Exit" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_exit()\fR \fBthr_exit()\fR \fBpthread_join()\fR \fBthr_join()\fR \fBpthread_detach()\fR \fB-\fR .TE .sp .SS "Functions Related to Thread Specific Data" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_key_create()\fR \fBthr_keycreate()\fR \fBpthread_setspecific()\fR \fBthr_setspecific()\fR \fBpthread_getspecific()\fR \fBthr_getspecific()\fR \fBpthread_key_delete()\fR \fB-\fR .TE .sp .SS "Functions Related to Signals" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_sigmask()\fR \fBthr_sigsetmask()\fR \fBpthread_kill()\fR \fBthr_kill()\fR .TE .sp .SS "Functions Related to IDs" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_self()\fR \fBthr_self()\fR \fBpthread_equal()\fR \fB-\fR \fB-\fR \fBthr_main()\fR .TE .sp .SS "Functions Related to Scheduling" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fB-\fR \fBthr_yield()\fR \fB-\fR \fBthr_suspend()\fR \fB-\fR \fBthr_continue()\fR \fBpthread_setconcurrency()\fR \fBthr_setconcurrency()\fR \fBpthread_getconcurrency()\fR \fBthr_getconcurrency()\fR \fBpthread_setschedparam()\fR \fBthr_setprio()\fR \fBpthread_setschedprio()\fR \fBthr_setprio()\fR \fBpthread_getschedparam()\fR \fBthr_getprio()\fR .TE .sp .SS "Functions Related to Cancellation" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_cancel()\fR \fB-\fR \fBpthread_setcancelstate()\fR \fB-\fR \fBpthread_setcanceltype()\fR \fB-\fR \fBpthread_testcancel()\fR \fB-\fR \fBpthread_cleanup_pop()\fR \fB-\fR \fBpthread_cleanup_push()\fR \fB-\fR .TE .sp .SS "Functions Related to Mutexes" .sp .TS tab( ); cw(3.85i) cw(1.65i) lw(3.85i) lw(1.65i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_mutex_init()\fR \fBmutex_init()\fR \fBpthread_mutexattr_init()\fR \fB-\fR \fBpthread_mutexattr_setpshared()\fR \fB-\fR \fBpthread_mutexattr_getpshared()\fR \fB-\fR \fBpthread_mutexattr_setprotocol()\fR \fB-\fR \fBpthread_mutexattr_getprotocol()\fR \fB-\fR \fBpthread_mutexattr_setprioceiling()\fR \fB-\fR \fBpthread_mutexattr_getprioceiling()\fR \fB-\fR \fBpthread_mutexattr_settype()\fR \fB-\fR \fBpthread_mutexattr_gettype()\fR \fB-\fR \fBpthread_mutexattr_setrobust()\fR \fB-\fR \fBpthread_mutexattr_getrobust()\fR \fB-\fR \fBpthread_mutexattr_destroy()\fR \fB-\fR \fBpthread_mutex_setprioceiling()\fR \fB-\fR \fBpthread_mutex_getprioceiling()\fR \fB-\fR \fBpthread_mutex_lock()\fR \fBmutex_lock()\fR \fBpthread_mutex_trylock()\fR \fBmutex_trylock()\fR \fBpthread_mutex_unlock()\fR \fBmutex_unlock()\fR \fBpthread_mutex_destroy()\fR \fBmutex_destroy()\fR .TE .sp .SS "Functions Related to Condition Variables" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_cond_init()\fR \fBcond_init()\fR \fBpthread_condattr_init()\fR \fB-\fR \fBpthread_condattr_setpshared()\fR \fB-\fR \fBpthread_condattr_getpshared()\fR \fB-\fR \fBpthread_condattr_destroy()\fR \fB-\fR \fBpthread_cond_wait()\fR \fBcond_wait()\fR \fBpthread_cond_timedwait()\fR \fBcond_timedwait()\fR \fBpthread_cond_signal()\fR \fBcond_signal()\fR \fBpthread_cond_broadcast()\fR \fBcond_broadcast()\fR \fBpthread_cond_destroy()\fR \fBcond_destroy()\fR .TE .sp .SS "Functions Related to Reader/Writer Locking" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_rwlock_init()\fR \fBrwlock_init()\fR \fBpthread_rwlock_rdlock()\fR \fBrw_rdlock()\fR \fBpthread_rwlock_tryrdlock()\fR \fBrw_tryrdlock()\fR \fBpthread_rwlock_wrlock()\fR \fBrw_wrlock()\fR \fBpthread_rwlock_trywrlock()\fR \fBrw_trywrlock()\fR \fBpthread_rwlock_unlock()\fR \fBrw_unlock()\fR \fBpthread_rwlock_destroy()\fR \fBrwlock_destroy()\fR \fBpthread_rwlockattr_init()\fR \fB-\fR \fBpthread_rwlockattr_destroy()\fR \fB-\fR \fBpthread_rwlockattr_getpshared()\fR \fB-\fR \fBpthread_rwlockattr_gettype_np()\fR \fB-\fR \fBpthread_rwlockattr_setpshared()\fR \fB-\fR \fBpthread_rwlockattr_settype_np()\fR \fB-\fR .TE .sp .SS "Functions Related to Semaphores" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBsem_init()\fR \fBsema_init()\fR \fBsem_open()\fR \fB-\fR \fBsem_close()\fR \fB-\fR \fBsem_wait()\fR \fBsema_wait()\fR \fBsem_trywait()\fR \fBsema_trywait()\fR \fBsem_post()\fR \fBsema_post()\fR \fBsem_getvalue()\fR \fB-\fR \fBsem_unlink()\fR \fB-\fR \fBsem_destroy()\fR \fBsema_destroy()\fR .TE .sp .SS "Functions Related to fork(\|) Clean Up" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_atfork()\fR \fB-\fR .TE .sp .SS "Functions Related to Limits" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fBpthread_once()\fR \fB-\fR .TE .sp .SS "Functions Related to Debugging" .sp .TS tab( ); cw(2.75i) cw(2.75i) lw(2.75i) lw(2.75i) . \fBPOSIX\fR \fBSolaris\fR \fB-\fR \fBthr_stksegment()\fR .TE .sp .SH LOCKING .SS "Synchronization" .sp .LP 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 (\fIoptimized frequent-read occasional-write mutex\fR), and semaphores. .sp .LP 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. .SS "MT \fBfork()\fR" .sp .LP If a threads program calls \fBfork\fR(2), it implicitly calls \fBfork1\fR(2), which replicates only the calling thread. Should there be any outstanding mutexes throughout the process, the application should call \fBpthread_atfork\fR(3C) to wait for and acquire those mutexes prior to calling \fBfork()\fR. .SH SCHEDULING .SS "POSIX Threads" .sp .LP Solaris supports the following three POSIX scheduling policies: .sp .ne 2 .mk .na \fB\fBSCHED_OTHER\fR\fR .ad .RS 15n .rt Traditional Timesharing scheduling policy. It is based on the timesharing (TS) scheduling class. .RE .sp .ne 2 .mk .na \fB\fBSCHED_FIFO\fR\fR .ad .RS 15n .rt First-In-First-Out scheduling policy. Threads scheduled to this policy, if not preempted by a higher priority, will proceed until completion. Such threads are in real-time (RT) scheduling class. The calling process must have the {\fBPRIV_PROC_PRIOCNTL\fR} privilege asserted in its effective set. .RE .sp .ne 2 .mk .na \fB\fBSCHED_RR\fR\fR .ad .RS 15n .rt Round-Robin scheduling policy. Threads scheduled to this policy, if not preempted by a higher priority, will execute for a time period determined by the system. Such threads are in real-time (RT) scheduling class and the calling process must have the {\fBPRIV_PROC_PRIOCNTL\fR} privilege asserted in its effective set. .RE .sp .LP In addition to the POSIX-specified scheduling policies above, Solaris also supports these scheduling policies: .sp .ne 2 .mk .na \fB\fBSCHED_IA\fR\fR .ad .RS 13n .rt Threads are scheduled according to the Inter-Active Class (IA) policy as described in \fBpriocntl\fR(2). .RE .sp .ne 2 .mk .na \fB\fBSCHED_FSS\fR\fR .ad .RS 13n .rt Threads are scheduled according to the Fair-Share Class (FSS) policy as described in \fBpriocntl\fR(2). .RE .sp .ne 2 .mk .na \fB\fBSCHED_FX\fR\fR .ad .RS 13n .rt Threads are scheduled according to the Fixed-Priority Class (FX) policy as described in \fBpriocntl\fR(2). .RE .SS "Solaris Threads" .sp .LP Only scheduling policy supported is \fBSCHED_OTHER\fR, which is timesharing, based on the \fBTS\fR scheduling class. .SH ERRORS .sp .LP In a multithreaded application, \fBEINTR\fR can be returned from blocking system calls when another thread calls \fBforkall\fR(2). .SH ATTRIBUTES .sp .LP See \fBattributes\fR(7) for descriptions of the following attributes: .sp .TS tab( ) box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . ATTRIBUTE TYPE ATTRIBUTE VALUE _ MT-Level MT-Safe, Fork 1-Safe .TE .sp .SH SEE ALSO .sp .LP \fBcrle\fR(1), \fBfork\fR(2), \fBpriocntl\fR(2), \fBpthread_atfork\fR(3C), \fBpthread_create\fR(3C), \fBlibpthread\fR(3LIB), \fBlibrt\fR(3LIB), \fBlibthread\fR(3LIB), \fBattributes\fR(7), \fBcancellation\fR(7), \fBprivileges\fR(7), \fBstandards\fR(7) .sp .LP \fIOracle Solaris 11.4 Linkers and Libraries Guide\fR .sp .LP \fIOracle Solaris 11.4 Multithreaded Programming Guide\fR .SH HISTORY .sp .LP Support for POSIX threads was added to Solaris in Solaris 2.5. .sp .LP Support for Solaris threads was added to Solaris in Solaris 2.2.