Sync Flashcards
What are the 2 main ways to structure parallel programs?
1) Threads communicate via shared data structures
2) Threads send messages directly to one another (only one possible in distributed systems)
What is the only way of structure parallel programs in distributed systems?
Threads sending messages directly to another
What is a shared memory segment?
Pages mapped into virtual memory of several processes
Name a flaw with Dekker’s Alg
Hard to generalise for 3 or more processes
Explain the Producer-Consumer problem
This works with a producer placing things into a holding buffer, and a consumer removing them. There is a variable, count (the number of items in the buffer), accessible to both. The consumer sleeps if the buffer is empty. The producer sleeps if buffer is full. These can be awakened by each other. In the case where the consumer reads count to be 0, then before it sleeps the scheduler allocates CPU to the producer. The producer adds an item to the buffer, then sends a wake up signal to the consumer. This signal is ignored as the consumer is awake. The CPU switches to consumer who immediately goes to sleep. The consumer will not wake up as no more signals to wake will be sent. The producer will keep adding items until buffer is full, then go to sleep. Both sleep forever.
What are the three tests for critical regions?
1) Mutual exclusion
2) Progress
3) Bound-waiting
Give an example of a race condition
Two processes, A & B, reading a file containing information about free memory slots and memory slots with files to print. If A reads and decides memory slot 2 is free, then interrupt occurs and B runs, B may store data in Memory slot 2. Control returns to A who then overwrites data in slot 2.
What conditions are required for having parallel processes cooperate effectively and efficiently using shared data?
1) No 2 processes may be in their critical regions at the same time
2) No assumptions made about speed or number of CPUs
3) No process running outside its critical region may block other processes
4) No process should have to wait forever to enter its critical region
Explain the process of disabling interrupts to achieve mutual exclusion. What is the problem with this?
Each processes disables interrupts upon entering its critical region, and reenables them just before leaving it. If a user forgets to enable interrupts again, problems occur. If the processor is multicore, interrupts will only be disabled on the CPU that the process is running on
Explain the process of lock variables to achieve mutual exclusion. What is the problem with this?
Processes have a single shared lock variable that defaults to 0 if no process is in critical region, but is changed to 1 when a process is in critical region. Processes must check lock variable before entering shared data. The problem is if a process reads and sees that the lock is 0, then an interrupt occurs and another process then sets the lock to 1, the first process will set the lock to 1 when control is returned to it.
Explain the process of strict alternation to achieve mutual exclusion. What is the problem with this?
Some variable keeps track of whose turn it is to enter the critical region. Once the critical region is left, the turn variable is changed to signify it is the turn of another process to access critical region. This uses busy waiting, which wastes CPU and so should generally be avoided. It wastes time if one process is significantly slower than another. Only strict alternation is allowed - no process may enter critical region twice in a row.
Explain the process of the TSL Solution to achieve mutual exclusion. What is the problem with this?
(test and set lock) A lot of computers have the following instruction: TSL RX, LOCK Reads the contents of the memory word lock into register RX. It can set and change the value of lock. During this process the memory bus is locked so other processes cannot make changes. Requires busy waiting
What issues arise with TSL solution and Peterson’s Solution to achieve mutual exclusion?
These both require busy waiting Priority Inversion Problem: Low priority process is running, high priority process wants to run, but has to wait. Low will never stop running, so high doesn’t get to enter the critical region
What is a semaphore?
A semaphore is a variable that stores the number of a particular resource that is available for future use. Two operations are wait and signal: signal increments semaphore, wait decrements it when semaphore > 0. if semaphore == 0, causes it to wait until a signal occurs.
What can we use to solve the Producer-Consumer problem? How?
Semaphores. 3 semaphores are used in this solution: full (how many slots are full), empty (how many slots are empty) and mutex (make sure buffer isn’t accessed by producer and consumer at same time).