Threads, P-threads and mutexes
#
Scope
#
- Thread concept. Single- and multiple-thread processes.
- Advantages of multi-threading. Scaling and Amdahl’s law.
- Multicore programming issues.
- User and kernel threads
- Multithreading models. Co-routines; fibers.
- Thread libraries: POSIX threads, Windows threads
- Implicit threading. Thread pools. OpenMP
- Threading issues:fork/exec, signal handling, cancellation, thread-local storage, scheduler activations
- POSIX threads API:
- thread creation (
pthread_create()
) and ending (pthread_exit(), exit(), pthread_cancel()
, returning from/exiting main()
function) - thread attributes
- passing parameters to thread function; returning result
- waiting for joinable thread (
pthread_join()
), detaching thread (pthread_detach
) - synchronization: motivation, using
mutex
to protect critical section related to some shared, concurrently accessed data - re-entrant and thread safe functions
- threads and signals: thread signal masks and their use
Reference
#
- Lecture presentation
- Lecture code samples
- Textbook: chapter 5 “Threads” - in 8th and 9th ed., or chapter 4 “Threads & Concurrency” - in 10th ed.
- Extra reading: The GNU C library documentation: 1.2.2.1 POSIX Safety Concepts, 12.5 Streams and Threads
- Excerpt from the POSIX Standard on threads cancellation
- Old Slides: Threads.pdf, POSIX_threads.pdf