[Go to CFHT Home Page] Man Pages
Back to Software Index  BORDER=0Manpage Top Level
    threads(3T) manual page Table of Contents

Name

threads, pthreads, libpthread, libthread - thread libraries: libpthread and libthread

Synopsis

Posix

cc [ flag ... ] file ... -lpthread [ -lposix4 library ... ]
#include <pthread.h>

Solaris

cc [ flag ... ] file ... -lthread [ library ... ]
#include <thread.h>
#include <sched.h>

MT-Level


Fork1-Safe MT-Safe

Description

Two threads libraries are available, POSIX and Solaris. Both implementations are interoperable, their functionality similar, and can be used within the same application. However, only POSIX threads are guaranteed to be fully portable to other POSIX-compliant environments. As indicated by the "Synopsis" section above, their use requires different source include files and different linking libraries.

Similarities

Most of the functions in both libraries, libpthread and libthread, have a counterpart in the other’s library. POSIX functions and Solaris functions, whose names have similar endings, usually have similar functionality, number of arguments, and use of arguments. i.e.:

POSIX Solaris
pthread_kill()thr_kill()
pthread_sigmask()thr_sigsetmask()
pthread_mutex_lock()mutex_lock()
sem_wait()sema_wait()

All POSIX threads function names begin with the prefix "pthread", with semaphore names being the exception.

Differences

POSIX

Solaris

Implementation

Creation

Exit

Thread Specific Data

Signal

ID

Scheduling

Cancellation

Mutex

Condition Variable

Reader/Writer Locking

Semaphore

fork() Clean Up Handling

Limits

Debugging

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_destroy()___
___thr_min_stack()
pthread_exit()thr_exit()
pthread_join()thr_join()
pthread_detach()___
pthread_key_create()thr_keycreate()
pthread_setspecific()thr_setspecific()
pthread_getspecific()thr_getspecific()
pthread_key_delete()___
pthread_sigmask()thr_sigsetmask()
pthread_kill()thr_kill()
pthread_self()thr_self()
pthread_equal()___
pthread_once()___
___thr_main()
___thr_yield()
___thr_suspend()
___thr_continue()
___thr_setconcurrency()
___thr_getconcurrency()
pthread_setschedparam()thr_setprio()
pthread_getschedparam()thr_getprio()
pthread_cancel()___
pthread_setcancelstate()___
pthread_setcanceltype()___
pthread_testcancel()___
pthread_cleanup_pop()___
pthread_cleanup_push()___
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_destroy()___
pthread_mutex_setprioceiling()___
pthread_mutex_getprioceiling()___
pthread_mutex_lock()mutex_lock()
pthread_mutex_trylock()mutex_trylock()
pthread_mutex_unlock()mutex_unlock()
pthread_mutex_destroy()mutex_destroy()
pthread_cond_init()cond_init()
pthread_condattr_init()___
pthread_condattr_setpshared()___
pthread_condattr_getpshared()___
pthread_condattr_destroy()___
pthread_cond_wait()cond_wait()
pthread_cond_timedwait()cond_timedwait()
pthread_cond_signal()cond_signal()
pthread_cond_broadcast()cond_broadcast()
pthread_cond_destroy()cond_destroy()
___rwlock_init()
___rw_rdlock()
___rw_tryrdlock()
___rw_wrlock()
___rw_trywrlock()
___rw_unlock()
___rwlock_destroy()
sem_init()sema_init()
sem_open()___
sem_close()___
sem_wait()sema_wait()
sem_trywait()sema_trywait()
sem_post()sema_post()
sem_getvalue()___
sem_unlink()___
sem_destroy()sema_destroy()
pthread_atfork()___
pthread_once()___
thr_stksegment()___

Locking

Synchronization

Multi-threaded behavior is asynchronous, and therefore, optimized for concurrent and parallel processing. Since 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. Solaris implements four synchronization mechanisms:

· mutex

· condition variable

· reader/writer locking (optimized frequent-read occasional-write mutex)

· semaphore

POSIX implements all but reader/writer locking.

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.

MT fork()

If a multi-threaded 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(3T) , to wait for and acquire those mutexes, prior to calling fork().

Files

Posix

/usr/include/pthread.h
/lib/libpthread.*
/lib/libposix4.*

Solaris

/usr/include/thread.h
/usr/include/sched.h
/lib/libthread.*

See Also

fork(2) , intro(3) , pthread_atfork(3T) , pthread_create(3T)

Errors

In a multi-threaded application, linked with libpthread or libthread, EINTR may be returned whenever another thread calls fork(2) , which calls fork1(2) instead.


Table of Contents