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