Process Synchronization Flashcards

(75 cards)

1
Q

What is the initial value of the counter in the motivating scenario?

A

5

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

What are the possible outcomes for the value of the counter after concurrent execution?

A

4, 5, or 6

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

Define race conditions.

A

A situation where several processes access and manipulate the same data (critical section) and the outcome depends on the order of access.

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

How can race conditions be prevented?

A

By synchronization, ensuring only one process manipulates the critical data at a time.

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

What is the critical section problem?

A

To design a protocol that ensures when one process is in its critical section, no other may be in its critical section.

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

What are the three main conditions to solve the critical section problem?

A
  • Mutual Exclusion
  • Progress
  • Bounded Waiting
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does mutual exclusion ensure?

A

If process P_i is executing in its critical section, no other processes can be executing in their critical sections.

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

What does progress mean in the context of the critical section problem?

A

If no process is executing in its critical section and some processes wish to enter, the selection of the next process cannot be postponed indefinitely.

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

What is bounded waiting?

A

A bound must exist on the number of times other processes can enter their critical sections after a request is made.

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

What does Dekker’s algorithm use to indicate if a process is ready to enter the critical section?

A

The turn variable.

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

What is the purpose of the flag array in Peterson’s solution?

A

To indicate if a process is ready to enter the critical section.

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

What does the test_and_set instruction do?

A

Writes to a memory location and returns its old value.

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

What is an atomic operation?

A

An operation that is performed without the possibility of interruption.

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

What is the role of hardware support in synchronization?

A

To implement critical section code efficiently using atomic hardware instructions.

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

True or False: The usage of interrupts is suitable for multicore systems.

A

False

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

What is the function of the compare_and_swap instruction?

A

It sets a variable to a new value only if it equals an expected value, executed atomically.

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

How does the compare_and_swap instruction guarantee mutual exclusion?

A

It ensures that only one process can change the value of a shared variable at a time.

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

Fill in the blank: The critical section must be executed by _______.

A

only one process at a time

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

What does the term ‘critical section’ refer to?

A

A segment of code where a process accesses shared resources.

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

What happens if multiple processes enter their critical sections simultaneously?

A

It can lead to data inconsistency.

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

What is the significance of disabling interrupts in uniprocessor systems?

A

It allows currently running code to execute without preemption.

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

What is the main drawback of disabling interrupts in multiprocessor systems?

A

It is generally too inefficient.

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

What is the expected behavior of a process that has made a request to enter its critical section?

A

It should not be indefinitely postponed from entering.

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

How does hardware support improve synchronization mechanisms?

A

By providing atomic operations that prevent race conditions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the main goal of mutual exclusion?
To prevent multiple processes from entering a critical section simultaneously.
26
Is bounded waiting guaranteed in the discussed mutual exclusion solution?
No, bounded waiting is not guaranteed.
27
What are the advantages of the mutual exclusion solution?
* Applicable to any number of processes * Simple and easy to verify * Can support multiple critical sections
28
What does the 'test_and_set' operation do in mutual exclusion?
It tests a variable and sets it to true atomically, ensuring only one process can acquire the lock.
29
What is a mutex lock?
A synchronization tool that protects a critical section by requiring processes to acquire and release a lock.
30
What is a spinlock?
A type of mutex lock that uses busy waiting to acquire the lock.
31
Define the semaphore.
A synchronization tool that provides more sophisticated ways for processes to synchronize their activities.
32
What are the two atomic operations associated with semaphores?
* wait() * signal()
33
What is a binary semaphore?
A semaphore that can only take values 0 or 1, often used to implement mutual exclusion.
34
What is the difference between a counting semaphore and a binary semaphore?
A counting semaphore can have a value in an unrestricted domain, while a binary semaphore is limited to 0 or 1.
35
What is deadlock?
A situation where two or more processes are waiting indefinitely for an event that can only be caused by one of the waiting processes.
36
What is starvation in the context of process synchronization?
Indefinite blocking where a process may never be removed from the semaphore queue.
37
What is priority inversion?
A scheduling problem where a lower-priority process holds a lock needed by a higher-priority process.
38
List the classical problems of synchronization.
* Bounded-Buffer Problem * Readers and Writers Problem * Dining-Philosophers Problem
39
What is the Bounded-Buffer Problem?
A problem involving N buffers, each capable of holding one item, where the producer and consumer must synchronize access.
40
What are the roles of the producer and consumer in the Bounded-Buffer Problem?
* Producer: produces items and adds them to the buffer * Consumer: removes items from the buffer and consumes them
41
In the Readers-Writers Problem, what is a reader?
A process that only reads shared data and does not modify it.
42
In the Readers-Writers Problem, what is a writer?
A process that can both read and write shared data.
43
What is the main problem in the Readers-Writers Problem?
To allow multiple readers to read concurrently while ensuring exclusive access for writers.
44
What is the Dining-Philosophers Problem?
A classical synchronization problem that illustrates the difficulty of allocating resources among processes without deadlock and starvation.
45
How many forks are available in the Dining-Philosophers Problem?
Five forks.
46
What is a potential solution to avoid deadlock in the Dining-Philosophers Problem?
Allow a philosopher to pick up their chopsticks only if both are available.
47
What is the role of semaphores in the Dining-Philosophers Problem?
One semaphore per fork to manage access to the forks.
48
What happens if each philosopher starts by picking their left fork?
It can lead to deadlock.
49
What is the purpose of the wait() operation in synchronization?
To decrement the semaphore value and potentially block the process if the value is less than or equal to zero.
50
What does the signal() operation do in synchronization?
It increments the semaphore value and may wake up a blocked process.
51
What is a semaphore value of -ve indicative of?
The number of processes waiting to acquire that semaphore.
52
What is the solution to starvation in semaphore queues?
Implementing a priority-inheritance protocol or ensuring fair access to resources.
53
What is the condition for a philosopher to pick up chopsticks?
Both chopsticks must be available
54
How does an odd philosopher pick up chopsticks?
First the left chopstick, then the right chopstick
55
How does an even philosopher pick up chopsticks?
First the right chopstick, then the left chopstick
56
What is a proposed solution to the dining philosophers problem?
Allow at most four philosophers to be sitting simultaneously at the table
57
Define monitors in concurrent programming.
High-level language constructs providing functionality equivalent to semaphores but easier to control
58
List the programming languages where monitors can be found.
* Concurrent Pascal * Java
59
What does a monitor contain?
* One or more procedures * An initialization sequence * Local data variables
60
What ensures mutual exclusion in a monitor?
Only one process can be active within the monitor at a time
61
What locks shared data in a monitor?
The monitor locks the shared data on process entry
62
What must be declared to allow a process to wait within a monitor?
A condition variable
63
What happens to a process when it invokes x.wait()?
The process is suspended until another process invokes x.signal()
64
What is the effect of the x.signal operation?
It resumes exactly one suspended process that invoked x.wait()
65
What is the solution function to the dining philosophers problem?
DP.pickup(i)
66
What synchronization method was used in Linux prior to kernel version 2.6?
Disables interrupts to implement short critical sections
67
What does Linux version 2.6 and later provide for synchronization?
* Semaphores * Atomic integers * Spinlocks
68
What is the pthreads API?
An OS-independent API that provides synchronization tools
69
List the synchronization tools provided by pthreads.
* Mutex locks * Condition variables
70
What is the syntax to create and initialize a mutex in pthreads?
#include pthread_mutex_t mutex; pthread_mutex_init(&mutex, NULL);
71
What is the function to acquire a mutex lock in pthreads?
pthread_mutex_lock(&mutex)
72
What is the function to release a mutex lock in pthreads?
pthread_mutex_unlock(&mutex)
73
What is the syntax to create and initialize a semaphore?
#include sem_t sem; sem_init(&sem, is_shared(0/1), 1);
74
What is the function to acquire a semaphore?
sem_wait(&sem)
75
What is the function to release a semaphore?
sem_post(&sem)