Fundamentals Flashcards
What are concurrent systems?
Several components working at any one time.
What is concurrent programming?
Writing programs which allow different parts of a system to execute concurrently and to co-operate.
What are the advantages of concurrent programming?
Processing can go faster
Sometimes easier to program than sequential systems
What are the disadvantages of concurrent programming?
Components can interfere with each other
Components need to communicate and cannot work independently
What is multitasking?
Two (single threaded) applications running on a PC
e.g. editor and file manager, can executed independently and also interact (drag a file over, etc)
What is multi-threading?
A thread is like a process, with a program consisting of multiple threads
What is the Hospital Porter scenario
Room for one patient, two different porters
Treatment room is too small, can cause collisions
Porters could find empty rooms
Synchronisation (multual and conditional) is needed to solve the problems
What is mutual synchronisation?
Only one thread/process can gain access at any one time
What is conditional synchronisation?
Threads can only execute when a condition is met
Why are threads used in concurrent systems?
Allow a single program multiple threads/paths of control
Lower overhead than processes, full complement of coordination mechanisms
Conceptually cleaner
Advantages of using threads in Concurrent Systems
Cheap - implemented at user level, no kernel resources
Efficient - no system calls or switching modes involved
Parallel execution - can make use of multi-CPUs
Higher Application Throughput - Puts I/O on different thread
Interactive Responsiveness - I/O responds faster
Better communication - threads share address space
Resources - Threads use a fraction of resource space
Distributed objects are inherently multi-threaded
Easy to write, understand, and debug
Shared standards - POSIX
Shares parent resources hence cheap to start
What is a disadvantage of using threads in Concurrent Systems?
Shares parent resources which is cheap to start but must worry about concurrent access. fork() takes a copy which is expensive to start but means no worrying over access later
What does a ‘normal’ program consist of?
Statements being executed in sequential order ie one thread of control
What does a ‘concurrent’ program consist of?
Set of sequential programs executing in ‘parallel’ with a process essentially being an executing program
Potentially parallel but resources can be shared and time-sliced (e.g. one processor)
What does a parallel program consist of?
Executions occur at the same time, usually using separate processors
What is a process?
Process is a program in execution
Kernel level entity
Single process can have multiple threads
What is a Thread?
Single line or stream of control
Created at user level
Thread essentially looks like a process
What are the 4 stages of threads?
New
Runnable
Blocked
Terminated
When is a thread new?
Created, but not yet running
When is a thread runnable?
When start is invoked
When is a thread Blocked?
- When sleep is called
- When suspend is called
- When thread calls wait
- When threads calls an operation that is blocking on input/output
When is a thread terminated?
If run method exits
OR
stop method is invoked
What does the thread method yield do?
Yields control away from that thread to others to allow them to temporarily execute
What does the thread method setDaemon(boolean) do?
Thread can be set as a Daemon, which means the JVM will exit even is Daemon Thread is still running
What are the two methods of creating threads?
Extend ‘Thread’ and override the run method
Implement runnable, provide a run method
Why is the extend ‘Thread’ method limited?
Because the class must be a subclass of Thread and cannot subclass another
What is time-slicing?
Threads are run for short periods of time and suspended
Resumes when it becomes their turn again
Threads of same priority share turns
How does a single process achieve concurrency?
Time-slicing
Does Java specify if the scheduler performs time slicing?
No
How would a user test for time slicing?
Define a thread class that will run forever
Create two of these threads and start them
If timesliced, 0 and 1 will intermix
If not timesliced, 0 will repeat forever
What is meant by Atomic action?
Action that can’t be interrupted by an instruction from another process.
Once an atomic action reads a variable, if subsequently re-read, it can be assumed it’ll remain the same.
What is Finite Progression Assumption?
If more than one process/thread can proceed, then we must consider all possibilities.
It is non-deterministic, however.
Assume if there is one to proceed then it will
What are interleavings?
An interleaving of a concurrent program is a list of atomic actions of its sequential programs.
Within the interleaving, each sequential program is listed in correct order, but the actions of different sequential components can be intermixed.
(t1, t2, u1, u2)
(t1, u1, t2, u2) both interleavings of same statement
What are Histories?
A history of a concurrent program is a possible interleaving of its atomic actions.