POSIX Threads: Semi-FAQ Revision 5.2
© 2001-2006 Michael M. Lampkin
email: michael.lampkin<at>ieee.org
Table of Contents:
- 4. POSIX THREADS / PTHREADS
- 4.1 Determining if a system implements POSIX threads?
- 4.2 How do I compile a threaded program?
- 4.3 How do I define a pthread?
- 4.4 How do you start a thread?
- 4.5 How do I exit / stop a thread?
- 4.6 How many threads can exist simultaneously?
- 4.7 Why you normally cannot normally create PTHREAD_THREAD_MAX threads
- 4.8 What is a thread attribute?
- 4.9 How do I create a variable for thread attributes?
- 4.10 How do I destroy a thread attribute variable?
- 4.11 How do I identify a specific thread?
- 4.12 How do I compare two threads?
- 4.13 What is a "joinable" thread?
- 4.14 How do you create a "joinable" thread?
- 4.15 How do you make an existing thread joinable?
- 4.16 How do I join a "joinable" thread?
- 4.17 What is a "detached" thread?
- 4.18 How do you create a "detached" thread?
- 4.19 How do you make an existing thread detached?
- 4.20 How do you tell if an existing thread is joinable or detached?
- 4.21 How do I tell if a thread is still executing and not terminated?
- 4.22 What are pthread_getconcurrency( ) and pthread_setconcurrency?
- 4.23 How do I "force" a CPU bound thread to give up the processor?
- 4.24 Why does threaded code sometimes segfault when using sleep( )?
- 4.25 Can I use SIGALRM with pthreads?
- 4.26 How do I modify the priority of a thread?
- 4.27 Why is my thread's priority being modified by the system?
- 4.28 Why do all my thread's change priority when I modify only one?
- 4.29 What is a "race condition"?
- 4.30 Can I use a C++ class function to start a thread?
- 4.31 Why do all threads block when one thread makes a blocking system call?
- 4.32 Why does my C / C++ program leak memory when I use pthread_exit( )?
- 4.99 Common problems and solutions.
- 5. PTHREAD ATTRIBUTES ( CONT. )
- 5.1 What is the thread Stack (Address and Size) Attribute(s)?
- 5.2 How can I determine if a system supports the Stack Attribute(s)?
- 5.3 How do you get/set the thread Stack Address and Size Attribute(s)?
- 5.4 How do I query an existing thread for its Stack Attribute(s)?
- 5.5 How do I modify the Stack Attribute(s) of an existing thread?
- 5.6 Why does my program crash / segfault when using Stack Attributes?
- 5.7 Can I use the pthread_attr_setstackaddr() function instead?
- 5.8 Can I use the pthread_attr_setstacksize() function instead?
- 5.9 Can I re-use an attribute object after setting the Stack Address?
- 5.10 What is the thread Guard Size Attribute?
- 5.11 How can I determine if a system supports the Guard Size Attribute?
- 5.12 How do I get/set the thread Guard Size Attribute?
- 5.13 Why doesn't setting both Guard Size AND Stack Attributes work as expected?
- 5.14 What is the thread Scheduling Policy Attribute?
- 5.16 What functions get/set the thread Scheduling Policy Attribute?
- 5.17 Scheduling policies in detail
- 5.18 What is the SCHED_FIFO scheduling policy?
- 5.19 What is the SCHED_OTHER scheduling policy?
- 5.20 What is the SCHED_RR scheduling policy?
- 5.21 What is the SCHED_SPORADIC scheduling policy?
- 5.22 How do I query an existing thread for its Scheduling Policy Attribute?
- 5.23 How do I modify the Scheduling Policy of an existing thread?
- 5.24 What is the thread Scheduling Parameter(s) Attribute?
- 5.25 What is the structure format for the Scheduling Parameter(s) Attribute?
- 5.26 What functions get/set the thread Scheduling Parameter(s) Attribute?
- 5.27 How do I query an existing thread for its Scheduling Parameter(s) Attribute?
- 5.28 How do I modify the Scheduling Parameter(s) Attribute of an existing thread?
- 5.29 What are the valid upper and lower priority values?
- 5.30 How do I set a thread's priority using the Scheduling Parameter(s) Attribute?
- 5.31 What is the thread Contention Scope Attribute?
- 5.32 How can I determine if a system supports the Contention Scope Attribute?
- 5.33 What functions get/set the thread Contention Scope Attribute?
- 5.34 When should I set the contention to PTHREAD_PROCESS_SCOPE?
- 5.35 When should I set contention to PTHREAD_SYSTEM_SCOPE?
- 6. POSIX MUTEXES
- 6.1 How do I determine if my implementation supports mutexes?
- 6.2 How do I create a mutex?
- 6.3 How do I destroy a mutex?
- 6.4 What is a mutex attribute?
- 6.5 How do I create a mutex attribute?
- 6.6 How do I destroy a mutex attribute (container)?
- 6.7 What are the available mutex attributes?
- 6.8 What is the mutex Type Attribute?
- 6.9 How can I determine if a system supports the mutex Type Attribute?
- 6.10 What functions get/set the mutex Type Attribute?
- 6.11 How do I query an existing mutex for its Type Attribute?
- 6.12 How do I modify the Type Attribute of an existing mutex?
- 6.13 What is the mutex Shared Attribute?
- 6.14 How can I determine if a system supports the mutex Shared Attribute?
- 6.15 What functions get/set the mutex Shared Attribute?
- 6.16 How do I query an existing mutex for its Shared Attribute?
- 6.17 How do I modify the Shared Attribute of an existing mutex?
- 6.18 What is the mutex Priority Ceiling Attribute?
- 6.19 How can I determine if a system supports the mutex Priority Ceiling Attribute?
- 6.20 What functions get/set the mutex Priority Ceiling Attribute?
- 6.21 How do I query an existing mutex for its Priority Ceiling Attribute?
- 6.22 How do I modify the Priority Ceiling Attribute of an existing mutex?
- 6.23 What is the mutex Protocol Attribute?
- 6.24 How can I determine if a system supports the mutex Protocol Attribute?
- 6.25 What functions get/set the mutex Protocol Attribute?
- 6.26 How do I query an existing mutex for its Protocol Attribute?
- 6.27 How do I modify the Protocol Attribute of an existing mutex?
- 6.28 What is deadlock?
- 6.29 What is priority inversion (with mutexes)?
- 6.30 How many mutex objects can exist at the same time?
- 6.31 How do I lock and unlock a mutex?
- 6.32 Can I test a mutex to see if it is locked?
- 6.33 Can I tell a thread to stop waiting to gain ownership of a mutex once it starts waiting?
- 6.34 Can I put a time limit on the amount of time a thread waits to obtain ownership of a mutex?
- 6.35 A thread crashed that owned a mutex, how do I unlock it?
- 6.36 Is a read write lock a mutex?
- 6.37 Is a spin lock a mutex?
- 6.38 Which thread gets mutex ownership if several are queued for it?
- 6.39 How do I emulate a recursive mutex?
- 6.40 What is thread starvation?
- 6.41 Can I use "volatile" instead of a mutex?
- 6.42 Are mutexes correct if I usually just read data in the critical section?
- 6.43 A simple example of using a mutex
- 7. POSIX CONDITION VARIABLES
- 7.1 How do I determine if my implementation supports condition variables?
- 7.2 How do I create a condition variable?
- 7.3 How do I destroy a condition variable?
- 7.4 What is a condition variable attribute?
- 7.5 How do I create a condition variable attribute?
- 7.6 How do I destroy a condition variable attribute?
- 7.7 What are the available condition variable attributes?
- 7.8 What is the condition variable Clock Attribute?
- 7.9 What is the condition variable Process-Shared Attribute?
- 7.10 How can I determine if a system supports the Process-Shared Attribute?
- 7.11 What functions get/set the Process-Shared Attribute?
- 7.12 How do I query an existing condition variable attribute for its Process-Shared Attribute?
- 7.13 How do I use a condition variable - using pthread_cond_wait( )?
- 7.14 How do I do a timed wait on a condition variable?
- 7.15 How do I do a timed wait on a condition variable using a relative time?
- 7.16 Why didn't the timed wait return after I modified the system clock?
- 7.17 How do I wake one thread suspended on a condition variable?
- 7.18 How do I wake ALL threads suspended on a condition variable?
- 7.19 What is the thundering herd problem?
- 7.20 Can anything else cause the thundering herd problem?
- 7.99 A small example of using a condition variable
- 8. PTHREADS & SIGNALS
- 8.1 What is a signal set and how do I create one?
- 8.2 How can I tell if a signal is in a specific signal set?
- 8.3 How do I get the signal mask of a thread?
- 8.4 How do I set the signal mask of a thread?
- 8.5 Can I use sigprocmask( ) instead of pthread_sigmask( )?
- 8.6 What is the signal mask for a newly created thread?
- 8.7 Using sigwait( ) to receive and process a signal
- 8.8 Using sigwaitinfo( ) to receive and process a signal
- 8.9 Using sigtimedwait( ) to receive and process a signal
- 8.10 How can I send a signal to a specific thread?
- 8.11 What is the "recommended" setup for signal handling with threads?
- 8.12 Why is the wrong thread receiving a signal?
- 8.13 A short example of pthreads and catching signals synchronously
- 9. POSIX SPIN LOCKS
- 9.1 How do I determine if my system supports spinlocks?
- 9.2 How do I create a spinlock?
- 9.3 How do I destroy a spinlock?
- 9.4 How many spinlocks can exist at the same time?
- 9.5 How do I lock and unlock a spinlock?
- 9.6 Can I test a spinlock to see if it is locked?
- 9.7 Can I specify how long a thread will spin on a spinlock?
- 9.8 A thread crashed that owned a spinlock, how do I unlock it?
- 9.9 Which thread gets spinlock ownership if several are spinning on it?
- 9.10 When should I use / not use a spinlock?
- 10. POSIX READ-WRITE LOCKS
- 10.1 How do I determine if my system supports read-write locks?
- 10.2 How do I create a read-write lock?
- 10.3 How many read-write locks can exist at the same time?
- 10.4 How do I destroy a read-write lock?
- 10.5 What is rwlock attribute?
- 10.6 How do I destroy a rwlock attribute?
- 10.7 What are the available rwlock attributes?
- 10.8 What is the rwlock Process Shared Attribute?
- 10.9 How can I determine if a system supports the rwlock Shared Attribute?
- 10.10 What functions get/set the rwlock Shared Attribute?
- 10.11 How do I find out if a rwlock is process private or shared?
- 10.12 How do I lock and unlock a read-write lock?
- 10.13 How do I request a lock for reading on a rwlock?
- 10.14 Can I limit the time waiting for a read lock on a rwlock?
- 10.15 Can I check if a rwlock would block a reader thread?
- 10.16 How do I request a lock for writing on a rwlock?
- 10.17 Can I check if a rwlock would block a writer thread?
- 10.18 Can I limit the time waiting for a write lock on a rwlock?
- 10.19 A thread crashed that owned a read-write lock, how do I unlock it?
- 10.20 Why are my reader threads suffering from starvation?
- 10.21 When should I use / not use a read-write lock?