Use this tag when the program performs its work using multiple concurrent threads of execution.
Multi-threading is a common model to implement SM in multi-cored machines, where threads share memory through shared variables. In this model of parallel programming, a processor can create multiple threads that will be executed in parallel. Each thread has its own stack, variables and ID, considered private state. For every thread there is a unique heap shared by all, considered shared memory.
In order to allow a volume of work to be most effectively and safely divided into multiple concurrent streams of execution, a number of critical areas need to be addressed.
- Scheduling: ensure worker tasks are able to progress independently and effectively (e.g. deadlock/livelock avoidance).
- Publication: ensure data altered in one thread is only visible to others as expected.
- Synchronization: ensure critical regions are protected from multiple concurrent updates causing data loss/corruption.
The underlying tenet of concurrent processing is Amdahl's law (graph). This law governs the diminishing amount of throughput that can be achieved by greater numbers of concurrent processors/cores. Therefore the overall aim of multi-threading is to minimize the amount of serial execution (exclusive locking) within any concurrent system.
Books
- "Threading in C#" (free e-book)
- "Java Concurrency in Practice"
- "C++ Concurrency in Action"
- "Principles of Concurrent and Distributed Programming"
- "Concurrent Programming on Windows"
- Java Threads, By Scott Oaks, Henry Wong
More information:
- Multithreading (computer architecture) (Wikipedia)
- Multithreading (software) (Wikipedia)