Unit 9 - Concurrency and Multithreading Flashcards
List 3 challenges of concurrent systems
Coordination
- Consolidating things after breaking program into processes that may be executed out of order
- Sync up between different processes
Memory Management
- How much memory does each process get
Scheduling
- Which process is active at what time
Deadlocks
- Two processes keep waiting for each other
Resource Starvation
Race Conditions
Threads with shared memory are sometimes interleaving on a
single processor core using a scheduling algorithm.
In Java, each thread is associated with an
object of type Thread or a class that extends Thread.
The following are some of the reasons that could make using multiple threads a better choice
- It is simpler to design the program as a system of concurrent threads, because the software system has several responsibilities that require its continual and constant attention all at the same time. Eg:
– The software system has to control multiple physical or virtual devices in a timely manner (eg embedded real-time systems, GUIs).
– The software simulates several independent active entities (eg computer games or mechanical system simulators). - The task is distributed over a network by its nature (eg an Internet phone system).
- The task is very resource-intensive and needs to make the best possible use of multiple processors or clustered computers (eg a web search engine).
A thread is launched using the
The thread object has to have a
start method of the associated object.
method run, which is executed by the new thread on launch and thus defines what the thread should be doing.
In Ada, threads are called
tasks
Shared memory is hard to manage correctly. Common problems include
race conditions, deadlocks and thread starvation.
Transactional memory is an approach to
managing shared data in way that facilitates safe concurrent access by multiple threads without locking.