Operating Systems (2) Flashcards

1
Q

Instruction Interleaving. When is it okay? When is it not okay?

A

Instructions from different processes get mixed together in the CPU.
It is okay for this to happen if the shared variables are saved to the same register. It is NOT okay for this to happen if the variables shared are saved on different registers, similar to having two copies of a variable.

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

How does instruction interleaving affect CPU?

A

It has no effect to the CPU, as it does not matter where the instructions come through from, nor does its order. The CPU will continue its work (fetch, decode, execute, interrupt).

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

How does instruction interleaving affect processes?

A

A process could have a different result than intended, especially if they share a variable.

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

How can we make sure interleaved processes give consistent results?

A

By keeping the shared variable saved onto one register.

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

What are the criteria needed to give consistent results? (Solve the critical section problem)

A

Mutual exclusion, bounded waiting, progress

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

Critical Section:

A

A section of code where variables will be shared with one or more processes.

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

Progress vs Bounding Waiting

A

Bounding waiting is when one process has a finite amount of time in an entry loop, and leaves by a trigger in another process. Progress is when all processes have a finite time in an entry loop and will all receive their triggers to move through their entire process.

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

Bakery Algorithm:

A

A critical section solution which is useful for multiple processes, and all criteria is met to solve the C.S. The entry loop has two variables with a boolean and an integer (atomic) that must both be set to be stuck waiting. If one process proceeds to the critical section, it will make all other processes wait their turn. When the process exits, it will change one of the variables, allowing another process to enter the critical section. (Software synchronization)

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

testandSet:

A

An atomic or uninterruptible method where a variable needed by the C.S. is received, and it’s set to true to return the variable. Multiple processes could create a boolean variable lock if one process has already entered the critical section. The boolean is initialized to false, but if the boolean is already true and sent testAndSet again, it will stay in the waiting loop until it is set to false, by leaving the C.S. (Hardware synchronization)

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

Semaphores:

A

Semaphores are a special integer (S) that can be treated like a boolean. It is used in two methods: wait and signal. If a process tries to enter while another is in the C.S. (S would be decremented already), it will be stuck in a wait queue (which checks to see if S is 0 or negative). Signal allows S to return to its initial state and exit the C.S. (OS synchronization) Note: Semaphores can also be used in a Bounded Buffer with it’s integer property.

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

Bakery Algorithm Advantages and Disadvantages:

A

It is adaptable for multiple processes. However, wait queue times are not controllable. (Which in turn makes it not very portable, since delay times are different on different systems.)

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

testandSet Adv. and Dis.:

A

Great when used with systems that give users access to it, but its neither portable to other systems, and so system specific.

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

Semaphores Adv. and Dis.:

A

Is used by many different operating systems and is very well tested by creators of OS’s. But still uses busy waiting.

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

When are the C.S. solutions efficient/inefficient?

A

Efficient at following all solution criteria. Inefficient in removing deadlocks completely and reducing the waste of CPU cycles.

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

What can be done to reduce CPU cycle waste?

A

By using the blocking method, which sends processes to a wait queue by the wait call, until they are sent into the ready queue by the signal call to eventually be run. (Timing is more controlled this way)

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

When does deadlocking happen with Semaphores?

A

It does happen! Page 98 example

17
Q

Deadlock:

A

When processes cannot get the resources needed to run, because it is held by another process.

18
Q

Deadlock conditions:

A

Mutual Exclusion, no preemption, hold/wait, circular wait.

19
Q

Safe State:

A

When processes are not deadlocked. This relates to safe sequence because a safe-sequence of processes keeps the system in a safe state.

20
Q

Deadlock Prevention: Mutual Exclusion

A

Helpful by using shared resources only.

21
Q

Deadlock Prevention: Hold and Wait

A

Processes must request and acquire all resources before they begin (using system calls), and can only request resources if they have none.

22
Q

Deadlock Prevention: No-Preemption

A

If a process has resources and cannot receive any more necessary ones, it will have to release those resources, and can only restart again when it has them all. Preemption of resources can be forced when the OS notices the resources a starting process needs is held by another process.

23
Q

Deadlock Prevention: Circular wait

A

By using a number system for the resources, processes would only be able to take higher-numbered resources FIRST, before lower numbered ones.

24
Q

Deadlock Prevention vs Avoidance

A

Prevention creates methods to address the issues that causes deadlocks, while avoidance uses the information given to the OS about the required resources to come up with an instruction sequence that will not encounter a deadlock.