Real-Time Synchronization Flashcards
What is a “resource”?
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.
What is a “shared resource”?
It is a resource that can be used by more than one tasks.
What is a “critical session”?
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)
What does “mutual exclusion” mean?
It is the fact that access to a shared resource is only given to one job at a time.
What is “synchronization”?
Synchronization is any constraint that imposes an order to the operations carried out by two or more concurrent jobs.
What is the difference between “mutual exclusion” and “synchronization”?
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)
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?
When all tasks perform only read operations.
When mutual exclusion is needed, which mechanism can be used to implement it? Explain how it works.
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.
When a task is said “blocked”?
When a task is waiting for an exclusive resource, a task is said to be blocked on that resource.
Explain the phenomenon “priority inversion”. Give an example.
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.
What is a “chained block”?
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.
What is the worst case of the chained block?
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.
What is “deadlock”? Give an example.
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 the “Priority Inheritance Protocol” works?
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.
Which problems are solved by the PIP?
Priority inversion