{ "q01": { "type": "single", "question": "\n\nTo solve the Dining Philosopher's problem, the book proposes the following\nsolution:\n\n\n", "responses": { "order": "Change the order in which the last philosopher acquires the forks.", "waiter": "Have a waiter direct which philosophers can eat.", "starve": "Just let some of the philosophers starve.", "rdrn": "Have philosophers eat in round-robin fashion.", "forks": "Buy more forks." } }, "q02": { "type": "blank", "question": "\nTwo types of non-deadlock concurrency bugs are:\n\n\n
    \n\n
  1. ____: These bugs occur when the assumption of atomicity is incorrect.
  2. \n\n
  3. ____: These bugs occur when the desired order of operations is\nnot enforced during execution.
  4. \n\n
\n" }, "q03": { "type": "blank", "question": "\n\nDeadlock occurs when the following four conditions hold:\n\n\n\n
    \n\n
  1. ____: There exists a circular chain of threads such that each\nthread holds one or more resources that are being requested by the next\nthread in the chain.
  2. \n\n
  3. ____: Resources cannot be forcibly removed from threads that are\nholding them.
  4. \n\n
  5. ____: Threads hold resources allocated to them while waiting for\nadditional resources.
  6. \n\n
  7. ____: Threads claim exclusive control of resources that they\nrequire.
  8. \n\n
\n" }, "q04": { "type": "multiple", "question": "\n\nWhich of the following are ways to prevent deadlock (choose all that apply)?\n\n\n", "responses": { "ordering": "Provide some form of ordering to circumvent circular waiting.", "holding": "Make sure we always acquire locks one at a time.", "livelock": "Prefer methods that utilize livelock instead of deadlock.", "lockfree": "Avoid locks by using atomic hardware instructions." } }, "q05": { "type": "blank", "question": "\n\nRather than prevent deadlock, we can instead try to avoid it by having a\nsmart ____ that will consider the dependencies between threads or by having a\nservice that ____ deadlock and provides ____ techniques.\n\n\n" }, "q06": { "type": "blank", "question": "\n

\n\nSuppose you and your friends are going to Salsa night hosted by our beloved\nRamzi. You are willing to dance, but only after at least 2\nof your friends have started dancing.\n\n

\n\n

Model this synchronization problem using POSIX threads\nand semaphores. Assume each person is represented as a\nthread that calls one of the corresponding functions below\n(you_dance() for yourself and friend_dance() for each of\nyour friends).

\n\n

Assuming the following global variables:

\n\n
\nsize_t MIN_FRIENDS = 2  // Minimum number of friends dancing before you will dance\nsize_t Friends     = 0  // Number of friends dancing\n\nSemaphore Lock     = 1\nSemaphore Dancing  = 0\n
\n\n

Select and order the following lines of code to implement each of the\nfunctions below:

\n\n
\nA. sem_wait(Lock)\nB. sem_post(Lock)\nC. sem_wait(Dancing)\nD. sem_post(Dancing)\nE. Friends++\nF. Friends--\nG. if Friends >= MIN_FRIENDS\nH. if Friends < MIN_FRIENDS\n
\n\n

\n

    \n
  1. Select and order the lines of code above to implement the\nyou_dance() function. ____
  2. \n\n
  3. Select and order the lines of code above to implement the\nfriend_dance() function. ____
  4. \n
\n

\n\n
\n

Put a single space between each line of code (ie. \"A B C\")).

\n
\n" } }