SHARE
TWEET

Untitled

a guest Oct 15th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Reading Materials:
  2.  
  3. * chapter 6.1-6.7
  4. * chapter 7.1-7.6
  5.  
  6. # Weekly Exercise:
  7.  
  8. * 6.10: The implementation of mutex locks provided in Section 6.5 suffers from busy waiting. Describe what changes would be necessary so that a process waiting to acquire a mutex lock would be blocked and placed into a waiting queue until the lock became available.
  9. * 6.14 Consider the code example for allocating and releasing processes shown in Figure 6.23.
  10.   * a. Identify the race condition(s).
  11.   * b. Assume you have a mutex lock named ```mutex``` with the operations ```acquire()``` and ```release()```. Indicate where the locking needs to be placed to prvent the race condition(s).
  12.   * c. Could we replace the integer variable ```int number_of_processes = 0``` with the atomic integer ```atomic_t number_of_processes = 0``` to prevent the race condition(s)?
  13. * 6.17 Show how to implement the ```wait()``` and ```signal()``` semaphore operations in multiprocessor environments using the ```test_and_set()``` instruction. The solution should exhibit minimal busy waiting.
  14. * 6.22 Discuss the tradeoff between fairness and throughput of operations in the readers-writers problem. Propose a method for solving the readers-writers problem without causing starvation.
  15.  
  16. * 7.8 Consider a system consisting of **m** resources of the same type being shared by **n** processes. A process can request or release only one resource at a time. Show that the system is deadlock free if the following two conditions hold:
  17.   * a. The maximum need of each process is between one resource and **m** resources.
  18.   * b. The sum of all maximum needs is less than **m + n**
  19.  
  20. * 7.9 Consider the version of the dining-philosophers problem in which the chopsticks are placed in the center of the table and any two of them can be used by a philosopher. Assume that requests for chopsticks are made one at a time. Describe a simple rule for determining whether a particular request can be satisfied without causing deadlock giventhe current allocation of chopsticks to philosophers.
  21. * 7.10 Consider again the setting in the preceding question. Assume now that each philosopher requires three chopsticks to eat. Resource requests are still issued one at a time. Describe some simple rules for determining whether a particular request can be satisfied without causing deadlock given the current allocation of chopsticks to philosophers.
  22.  
  23. * 7.12 Consider the following snapshot of a system:
  24.  
  25. |          | Allocation | Max      |
  26. | -------- | ---------- | -------- |
  27. |          | A B C D    | A B C D  |
  28. | $P_0$    | 3 0 1 4    | 5 1 1 7  |
  29. | $P_1$    | 2 2 1 0    | 3 2 1 1  |
  30. | $P_2$    | 3 1 2 1    | 3 3 2 1  |
  31. | $P_3$    | 0 5 1 0    | 4 6 1 2  |
  32. | $P_4$    | 4 2 1 2    | 6 3 2 5  |
  33.  
  34.  
  35. Using the banker's algorithm, determine whether or not each of the following states is unsafe. If the state is safe, illustrate the order in which the process may complete. Otherwise, illustrate why the state is unsafe.
  36.   * a) **Available** = (0, 3, 0, 1)
  37.   * b) **Available** = (1, 0, 0, 2)
  38.  
  39. Figure 6.23 - Allocating and releasing processes
  40.  
  41. ```
  42. #define MAX_PROCESSES 255
  43. int number_of_processes = 0
  44.  
  45. /* the implementation of fork() calls this function */
  46. int allocate_processes() {
  47.  int new_pid;
  48.  
  49.  if (number_of_processes == MAX_PROCESSES)
  50.   return -1;
  51.  else {
  52.   /* allocate necessary process resources */
  53.   ++number_of_processes;
  54.  
  55.   return new_pid;
  56.  }
  57. }
  58.  
  59. /* the implementation of exit() calls this function */
  60. void release_processes() {
  61.  /* release process resources*/
  62.  --number_of_processes;
  63. }
  64. ```
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top