Operating Systems Concurrency (PPT 4-5) Flashcards

1
Q

What is Concurrency?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Synchronisation?

A

It is when one or more processes is forced to wait until another process has completed a vital task.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is Signalling?

A

This is when processes can talk to each other with basic signals or use messages. Important part is that processes communicate with each other

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are the three problems Concurrency can bring?

A
  • Race Conditions
  • Deadlock
  • Starvation
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a Race Condition?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How is a critical section of program code defined?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is mutual exclusion?

A

The execution of a critical piece of code must be mutually exclusive to the execution of any other such critical piece of code.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the six requirements of Mutual Exclusion?

A
  • 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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

How does an Interrupt Oriented Solution to race conditions work?

A

Just before we run a critical section, all interrupts are disabled. Once the critical section is finished, interrupts are re-enabled.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are Special Machine Instructions?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is a Test and Set solution to race conditions?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is a Semaphore?

A

These are a high level implementation of the low level instructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How do Semaphores work?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the Integer Count and Queue?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What do wait and signal do in a Semaphore?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is a binary Semaphore?

A

It is similar to a normal semaphore except the value can only be 1 or 0.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What are the advantages of Semaphores?

A
  • Simple
  • Intuitive
  • Flexible
  • Quick and easy to implement
18
Q

What are the disadvantages of Semaphores?

A
  • 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
19
Q

How is test and set used within semaphores?

A

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

20
Q

What is the producer/consumer problem?

A
  • 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
21
Q

What is a bounded buffer?

A

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.

22
Q

What is a Monitor?

A

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

23
Q

What is Message Passing?

A

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

24
Q

What are Simple Message Primitives?

A

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

25
Q

How does message passing link in with synchronisation?

A

A blocking send or receive means that the calling process waits until a message is received or delivered.

A non blocking send or receive means that the sender posts and forgets while the receiver comes away empty handed if the message is not available immediately.

If a system implements a blocking receive mechanism, there is usually a command to check for available messages

26
Q

What is an Exchange Instruction?

A

It is something that can exchange contents of an internal register with the contents of a memory location in one action. Means that a processor can set a variable in memory and fetch its previous state from memory in one atomic action.

27
Q

What is Deadlock?

A

This is the blocking of a set of processes due to an unfortunate distribution of resources between processes. It happens when resources are so divided up between processes that each needs a resource from another and therefore none can finish

28
Q

What is Starvation?

A

This is the indefinite prevention of a process progressing due to continued denial of access to a resource

29
Q

What are Re-usable Resources?

A

These are global resources that can be temporarily used exclusively by one process but are eventually released and then available to others

30
Q

What are Consumable Resources?

A

These are entities that are (continuously) created and made available for processes to uses. When a process acquires such a resource, it usually destroys it and it is not released back for general use

31
Q

What are the four conditions for deadlock to occur?

A
  • Mutual Exclusion: Only one process can use a resource at one time
  • Hold and Wait: Once a process has acquired a resource it is not prepared to relinquish it whilst waiting to acquire other resources
  • No pre-emption: No process can be forced to relinquish a resource
  • Circular Wait: A closed chain of processes in which each one is waiting for another to release a resource
32
Q

How do we prevent the Mutual Exclusion condition for deadlock?

A

You can’t, it is essential to the running of a modern operating system.

33
Q

How do we prevent Hold and Wait condition for deadlock?

A

We have to prevent a process from holding onto resources while waiting for others. It could possibly do this by making it get all of resources at one point but this is inefficient

34
Q

How can we prevent the no pre-emption condition for deadlock?

A

We can make a process periodically record the state of the resource and itself, so it can re-create the scenario and start again from that point. When a process requests unavailable resources, two common things could happen: The process gives up all its resources and attempts again later or the OS forces the process to give up its resources

35
Q

How do we prevent the Circular Wait condition for deadlock?

A

Resources have to be ordered and “lined up” in some way. Each resource travels along the line at its own pace but must pick resources it wants as it passes them

36
Q

What is Deadlock Detection?

A

This approach assumes that deadlocks don’t happen often. Preventing a deadlock costs efficiency so this says if one happens, we will deal with it. Many mathematical algorithms for detecting if one has happened

37
Q

How can we break a deadlock?

A

Four possible ways:

1) Kill all the deadlocked processes. Simple and easy but drastic
2) If check-pointing is implemented, force all processes back to their last state and restart. Random factors will likely stop deadlock
3) Kill processes one at a time until deadlock stops
4) Pre-empt resources until the deadlock is broken

These actions take no account of the possible damage but do try to avoid it

38
Q

How could we avoid a Deadlock?

A

Can achieve this by controlling allocation of resources. Resources only granted if deadlock is avoided. Have to build a system to keep track of what resources are in use and the maximum requirement each process has for each type of resource

39
Q

What is Process Initiation Denial?

A

This is when a process can start only if the sum of its and all currently running processes’ maximum requirements is less than or equal to the total available. It is not optimal as it assumes the worse case scenario that all running processes will want all their resources at the same time

40
Q

What is Resource Allocation Denial?

A

This is a dynamic process which kicks in when a resource is requested. The OS keeps sufficient resources to ensure that there is at least one way in which all processes can complete- a safe state. It involves reserving enough that one process can receive everything it requires.

41
Q

What is the best strategy for preventing Deadlock?

A

There isn’t a single best way as none of the previous strategies are perfect. The best performance can be achieved by using a combination of techniques