Real-Time Synchronization Flashcards

1
Q

What is a “resource”?

A

A resource is any software structure that can be used by a process to advance its execution. Ex. Data structure, set of variables, main memory area, file.

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

What is a “shared resource”?

A

It is a resource that can be used by more than one tasks.

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

What is a “critical session”?

A

It is the part of the code of a job that accesses a shared resource. (slides definition)

or

It is a piece of code executed under mutual exclusion constraints. (book definition)

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

What does “mutual exclusion” mean?

A

It is the fact that access to a shared resource is only given to one job at a time.

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

What is “synchronization”?

A

Synchronization is any constraint that imposes an order to the operations carried out by two or more concurrent jobs.

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

What is the difference between “mutual exclusion” and “synchronization”?

A

Mutual exclusion focuses on ensuring consistency of data, but does not ensure that all jobs will eventually access the resource and does not ensure any order.

Synchronization focuses on ensuring order of “events”, but is not limited to share resources (ex. precedence constrains)

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

In a system without synchronization strategy and several preemptive tasks that share a resource. Under which conditions can all tasks access the same resource at the same time without compromising consistency?

A

When all tasks perform only read operations.

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

When mutual exclusion is needed, which mechanism can be used to implement it? Explain how it works.

A

OS constructs that can be accessed in atomic operations. For example, semaphores.
Semaphores are composed by three basic operations:
1. init() - initializes the semaphore
2. wait() - request semaphore. If granted, then all other jobs requesting same semaphore will be blocked
3. signal() - release semaphore. Whenever it is called, it triggers blocked job with highest priority.

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

When a task is said “blocked”?

A

When a task is waiting for an exclusive resource, a task is said to be blocked on that resource.

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

Explain the phenomenon “priority inversion”. Give an example.

A

Priority inversion occurs when a higher priority task is being unnecessary delayed by lower priority tasks.
Supposed a system running three tasks (T1, T2, T3). The priority of the tasks are equal to their number and as lower the number is, higher is the priority. T1 and T3 share an resource (R1). T3 starts to execute and gets the access to the shared resource. After a while, it is preempted by T1. T1 executes until it needs access to the shared resource R1 (simple blocking). Then T3 continues to execute, but it is preempted by T2 (higher priority than T3) and starts to execute delaying task T1 execution unnecessarily (priority inversion). After T2 completes its execution, T3 runs until it frees R1. From this point, T1 gets access to R1 and is able to continue its execution.

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

What is a “chained block”?

A

Consider tasks T1, T2 and T3 with decreasing priorities that share two semaphores Sa and Sb. Suppose that T1 needs sequentially access to Sa and Sb, T2 accesses Sb and T3 access Sa. Also suppose that T3 locks Sa and it is preempted by T2 within its critical section. Similarly, T2 locks Sb and it is preempted by T1 within its critical section. In this situation, when attempting to use its resources, T1 is blocked for the duration of two critical sections, once wait for T3 to release Sa and then to wait for T2 to release Sb.

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

What is the worst case of the chained block?

A

If T1 (highest priority task on the system) accesses n distinct semaphores that have been locked by n lower priority tasks, T1 will be blocked for the duration of n critical sections.

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

What is “deadlock”? Give an example.

A

Deadlock is a situation in which two or more competing actions are each waiting for the other to finish, and thus neither ever does.

Consider two tasks (T1 and T2) that use two semaphores (Sa and Sb) in a nested fashion but in reverse order. Now suppose that, at time t1, Task 2 (T2) locks semaphore Sb and enters its critical section. At time t2, T1 preempts T2 before it can lock Sa. At time t3, T1 locks Sa, which is free, but then is blocked on Sb at time t4. At this time, T2 resumes and continues the execution. At time t5 a deadlock occurs, when T2 attempts to lock Sa.

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

How the “Priority Inheritance Protocol” works?

A

When a task Ti blocks one or more higher-priority tasks, it temporarily assumes (inherits) the highest priority of the blocked tasks. This prevents medium-priority tasks from preempting Ti and prolonging the blocking duration experienced by the higher-priority tasks.

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

Which problems are solved by the PIP?

A

Priority inversion

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

Which problems are not solved by the “Priority Inheritance Protocol”?

A

Chained blocking and deadlock.

17
Q

Which protocol solves chained blocking and deadlock problems?

A

Priority Ceiling Protocol (PCP)

18
Q

How does PCP (“Priority Inheritance Protocol”) work?

A

Each semaphore has a static priority ceiling value defined as:
- maximum priority of all tasks that may use it:
ceil(S) = highest priority of all tasks that will request S
- calculated offline
Each task has an assigned static priority (may change at run-time due to priority inheritance).
Same run-time mechanism as PIP but if a task i request semaphore S the request is granted if:
- S not already allocated to some other task
AND
- priority of task i is higher than priority ceilings of semaphores currently locked by tasks other than task i at that time.

otherwise task i is blocked by task j that holds semaphore with highest ceiling. Task j executes with priority of task i.

19
Q

What is the schedulability test works for PCP?

A

Response time analysis + duration of the longest critical session (Bi), since basic algorithm assumptions are violated.
Ri = Ci + Bi + sum { ceiling[Ri/Tj] * Cj , for all j in hp(i)}

20
Q

What is the maximum blocking time in PCP?

A

It is the duration of the longest critical session Bi.

21
Q

What is the difference between IPCP and PCP?

A

The job priority of task on PCP is raised when higher priority blocked, while on IPCP it is raised as soon as it locks the semaphore.

22
Q

Which are the disadvantages of IPCP?

A

Priorities may be raised unnecessarily and lower priority tasks delay higher priority tasks without blocking as well.

23
Q

How does the Stack Resource Policy (SRP) extends PCP?

A

It extends in three essential points:

  1. It allows the use of multi-unit resources;
  2. It supports dynamic priority scheduling;
  3. It allows the sharing of runtime stack-based resource.
24
Q

What is the essential difference between Stack Resource Policy and Priority Ceiling Protocol from the scheduling point of view?

A

The main difference is on the time at which a task is blocked. On SRP a task is blocked at the time it attempts to preempt, while on PCP the block occurs at the time it makes its first resource request. This early blocking slightly reduces concurrency but saves unnecessary context switches, simplifies the implementation of the protocol, and allows the sharing of runtime stack resources.