For questions regarding multi-threading, the ability of a computer or a program to perform work concurrently or asynchronously by utilizing multiple concurrent streams of execution (generally referred to as threads).
Multi-threading is a common model to implement SM in multi-cored machines, where threads share memory through shared variables. In this model in 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, then 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.
Frequently Asked Questions
- What's the difference between the atomic and nonatomic attributes?
- What's the difference between Invoke() and BeginInvoke()
- "implements Runnable" vs "extends Thread" in Java
- Difference between wait() and sleep()
- What are the differences between various threading synchronization options in C#?
- What is the difference between a process and a thread?
- What is meant by "thread-safe" code?
- What is a race condition?
- What are the "things to know" when diving into multi-threaded programming in C++
- How should I unit test threaded code?
- What is a daemon thread in Java?
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
- The Art of Multiprocessor Programming
More information:
- Multithreading (computer architecture) (Wikipedia)
- Multithreading (software) (Wikipedia)
Related tags
concurrencythread-safetypthreadsthreadpoolcoroutinefibersgreen-threadslightweight-processeslwt