Threads & Concurrency
by Ahmed Alafoori
1. Multicore Programming
1.1. Concurrency supports more than one task making progress
1.2. Parallelism implies a system can perform more than one task simultaneously
1.2.1. device drivers
1.2.2. file systems
1.2.3. virtual memory manager
1.2.4. windowing system
1.2.5. security services
1.3. Multicore or multiprocessor systems putting pressure on programmers, challenges include:
1.3.1. Dividing activities
1.3.2. Balance
1.3.3. Data splitting
1.3.4. Data dependency
2. Implicit Threading
2.1. Growing in popularity as numbers of threads increase, program correctness more difficult with explicit threads
2.2. Creation and management of threads done by compilers and run-time libraries rather than programmers
2.2.1. OpenMP
2.3. Five methods explored
2.3.1. Fork-Join
2.3.2. Thread Pools
3. Scheduler Activations
4. Both M:M and Two-level models require communication to maintain the appropriate number of kernel threads allocated to the application
5. Scheduler activations provide upcalls - a communication mechanism from the kernel to the upcall handler in the thread library
6. This communication allows an application to maintain the correct number kernel threads
7. Multithreading Models
8. Many-to-One
9. One-to-One
10. Many-to-Many
11. User Threads and Kernel Threads
12. User threads - management done by user- level threads library
13. Three primary thread libraries
14. Kernel threads - Supported by the Kernel
15. Motivation
15.1. Multiple tasks with the application can be implemented by separate threads
15.1.1. Update display
15.1.2. Fetch data
15.1.3. Spell checking
15.1.4. Answer a network request
15.2. Can simplify code, increase efficiency
15.3. Kernels are generally multithreaded
15.4. Most modern applications are multithreaded
16. Benefits
16.1. Scalability – process can take advantage of multicore architectures
16.2. Responsiveness – may allow continued execution if part of process is blocked, especially important for user interfaces
16.3. Resource Sharing – threads share resources of process, easier than shared memory or message passing
16.4. Economy – cheaper than process creation, thread switching lower overhead than context switching
17. System Calls
17.1. provide interface between a running program and the OS.
17.2. types of system calls
17.2.1. file management
17.2.2. deivce management
17.2.3. information maintenance
17.2.4. communications