part3 Flashcards
What is synchronisation?
The limitation of possible program traces by coordinating execution such that certain conditions are satisfied.
E.g., certain invariant is satisfied and/or execution has some desired property
What is an invariant?
an assertion that holds at all control points, such as mutual exclusion being maintained or y being less than or equal to x
What does action synchronisation rely on?
Action counting and invariants on the counting
If A is an action in a program, what does cA denote?
The number of completed executions of A
What is a topology invariant?
An invariant derived directly from the program text
E.g., two actions always occuring one after the other
What two things is action synchronisation specified by? What are such inequalities referred to as?
Inequalities on:
- Action counts
- Program variables directly related to this counting
Synchronisation conditions or synchronisation invariants
What does P(s) refer to? How about V(s)?
P(s): <await(s>0)>; s=s-1;
V(s): <s = s + 1>
What are the primary two semaphore invariants? What invariant arises from these two?
S0: S >= 0
S1: s = s0 + cV(s) - cP(s)
S2: cP(s) <= s0 + cV(s)
What is the progress property of semaphores?
Blocking is only allowed if the safety properties would be violated
What is the action synchronisation solution in general? Specifically, give a collections of tasks/threads executing actions A,B,C,D and the synchronisation:
SYNC: a * cA + c * cC <= b * cB + d * cD + e for non-negative constants a,b,c,d,e
Introduce a semaphore s, s0 = e and replace:
A -> P(s)^a; A
C -> P(s)^c; C
B -> B; V(s)^b
D -> D; V(s)^d
What does sem_t *sem declare?
A pointer to a semaphore object, which will be used for synchronization.
What function is used to open and create a named semaphore?
sem_open(name, flags, mode, init-val)
In sem_open, what does the name parameter represent? What does the flags parameter in sem_open determine? What is the purpose of the mode parameter in sem_open? What does the init-val parameter in sem_open define?
A system-wide unique name for the semaphore.
The operation to be performed.
To specify the file permissions.
The initial value of the semaphore.
What function is used to close a semaphore in the current process while keeping it accessible to others?
sem_close(sem)
Which function removes a named semaphore from the system? When is a named semaphore fully removed from the system?
sem_unlink(name)
When no process is using it.
What does sem_init(sem, pshared, init-val) do? In sem_init, what does the pshared parameter indicate?
Initializes an unnamed semaphore.
Whether the semaphore is shared across processes or just threads within a process.
What function is used to destroy an unnamed semaphore? What happens if you use a semaphore after it has been destroyed with sem_destroy?
sem_destroy(sem)
It must not be used, as its resources are released.
What does sem_wait(sem) do?
Attempts to decrement (lock) the semaphore; if the semaphore value is greater than zero, it decrements it. If the value is zero, it blocks until the semaphore becomes available.
How does sem_trywait(sem) differ from sem_wait(sem)?
sem_trywait does not block; it attempts to decrement/lock the semaphore and returns an error if not possible.