Operating Systems Concurrency (PPT 4-5) Flashcards
What is Concurrency?
It is:
-Many independent processes (unknowingly sharing resources)
-Several co-operating processes
-One multi-threaded program
on a machine with one or more processors or in a distributed system
What is Synchronisation?
It is when one or more processes is forced to wait until another process has completed a vital task.
What is Signalling?
This is when processes can talk to each other with basic signals or use messages. Important part is that processes communicate with each other
What are the three problems Concurrency can bring?
- Race Conditions
- Deadlock
- Starvation
What is a Race Condition?
It is whenever two or more processes manipulate a global resource in a way that it is possible an incorrect result can be produced
How is a critical section of program code defined?
It is any piece of code that has to be run under the assumption that no other process is executing a similar, related piece of code
What is mutual exclusion?
The execution of a critical piece of code must be mutually exclusive to the execution of any other such critical piece of code.
What are the six requirements of Mutual Exclusion?
- Must allow only one process into a critical section of program code at any one time
- A process halting in non-critical code must do so without interfering with any other process
- Process must (eventually) be allowed into its critical section. No deadlock or starvation.
- First come: Immediately served
- No assumption about speed or quantity of processes involved
- Critical sections must have finite duration
How does an Interrupt Oriented Solution to race conditions work?
Just before we run a critical section, all interrupts are disabled. Once the critical section is finished, interrupts are re-enabled.
What are Special Machine Instructions?
They are special instructions that help with mutual exclusion. They are atomic so can’t be pre-empted or sub-divided. RAM is also so organised that the CPU can only access a particular memory location any one time so sequential access is guaranteed
What is a Test and Set solution to race conditions?
This means that a boolean is tested when arriving at the critical code. If it is 1, the process is blocked and avoid the critical section if possible. If it is 0, the boolean is set to 1 and the process enters the critical section. Once it is finished, the boolean is set to 0
What is a Semaphore?
These are a high level implementation of the low level instructions.
How do Semaphores work?
Semaphores allow two or more processes to communicate using signals. A process can be forced to stop at a particular point until it receives a signal from another process. To send a signal, use the primitive signal(s). To receive a signal, use the primitive wait(s). If signal is not sent, wait blocks the progress
What is the Integer Count and Queue?
A semaphore contains a record with the integer count and a queue. Queue contains a list of waiting processes (if any are waiting). Count can be initialised to any non-negative integer value (often 1 as there is 1 available instance of the resource). Queue will start empty
What do wait and signal do in a Semaphore?
Wait
-decrements the semaphore count. If < 0 then process is blocked and added to queue
Signal
-increments the semaphore count. If count =<0, one waiting process is removed from the queue and placed on the ready list
What is a binary Semaphore?
It is similar to a normal semaphore except the value can only be 1 or 0.