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.
What are the advantages of Semaphores?
- Simple
- Intuitive
- Flexible
- Quick and easy to implement
What are the disadvantages of Semaphores?
- Easy to make mistakes
- Difficult to prove processes are correct
- Programmer is responsible for ensuring correct usage
- Processes frequently have to co-operate in their use of Semaphores. This breaks the isolation/modularisation of processes
How is test and set used within semaphores?
Both wait and signal are themselves critical code so must be atomic. Need test and set instructions within wait and signal to ensure mutual exclusion. This is dealt with by the low level primitives
What is the producer/consumer problem?
- One or more producers are generating data and placing it into a buffer
- One consumer is taking data out of the buffer
- Use semaphores to control access.
- Assume use of bounded buffer
What is a bounded buffer?
It is a buffer with a finite size. It has two pointers, in and out. When an item is placed in, in is incremented. When an item is removed, out is decremented. When in and out are equal, there is nothing in the buffer.
What is a Monitor?
It is a software module that consists of one or more procedures, an initialisation section and hidden, local data. The outside world can only see the procedures and the local data can only be manipulated within the procedures. Entry into the monitor is through a procedure call. Only one process can be executing in the monitor at any one time. Any other process that is inside the monitor is suspended
What is Message Passing?
In both the monitor and semaphores, processes interact by signalling. All processes have to know what the implicit message is behind each signal. Far greater flexibility is achieved if one process can actually pass an explicit message to one or more other processes
What are Simple Message Primitives?
The minimum requirement for processes to pass messages to each other is a pair of instructions:
send(destination,message)
receive(source,message)
Message Passing Interface (MPI) is a standard language for passing messages