{ "q01": { "type": "blank", "question": "\n\nA ____ is a synchronization primitive that consists of an ____ value that\nwe can manipulate with two routines:\n\n\n
    \n\n
  1. ____: This function decrements the value of the semaphore and\n waits if the value of the semaphore is negative.
  2. \n\n
  3. ____: This function increments the value of the semaphore and\n then wakes up any waiting threads.
  4. \n \n
\n" }, "q02": { "type": "multiple", "question": "\n\nRegarding using semaphores to implement locks and condition variables,\nwhich of the following statements are true (choose all that apply)?\n\n\n", "responses": { "lock_init": "To make a lock (binary semaphore), we initialize the semaphore to 1.", "cond_init": "To make a condition variable, we initialize the semaphore to 1.", "lock_call": "To make a lock (binary semaphore), we first sem_post, perform the critical section, and then sem_wait", "cond_call": "To make a condition variable, we use sem_post to signal and sem_wait to wait." } }, "q03": { "type": "multiple", "question": "\n\nRegarding reader-writer locks, which of the following statements are true\n(choose all that apply)?\n\n\n", "responses": { "concurrency": "Reader-writer locks allow for multiple concurrent readers as long as there are no writers.", "writers": "Reader-writer locks suspend all readers once a writer requires access.", "starvation": "Reader-writer locks are prone to starvation problems.", "overhead": "Reader-writer locks generally improve performance over simple and fast locking primitives." } }, "q04": { "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." } }, "q05": { "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" }, "q06": { "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" }, "q07": { "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." } }, "q08": { "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" }, "q09": { "type": "blank", "question": "

\n\nSuppose you and your friends are going slacklining. Unfortunately,\nthe slackline can only support up to three people on it at a time.\u00a0\nTherefore, if they are many people, they will need to wait before they can\nget onto the slackline.\n\n

\n\n

Assuming each person performs the following procedure:

\n\n
\nget_on()\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 // Get on slackline if there is enough room\ndo_slack_line() \u00a0 // Attempt to walk across slackline\nget_off() \u00a0 \u00a0 \u00a0 \u00a0 // Get off of slackline\n
\n\n

Model this synchronization problem using POSIX threads,\nmutexes, or condition variables. Assume each person is\nrepresented as a thread that calls the functions above to get on the\nslackline, cross the slackline, and then get off the slackline.

\n\n

Assuming the following global variables:

\n\n
\nsize_t CAPACITY = 3  // Maximum number of people on slackline\nsize_t Slackers = 0  // Current number of people on slackline\n\nMutex  Lock     \nCond   Line\n
\n\n

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

\n\n
\nA. mutex_lock(Lock)\nB. mutex_unlock(Lock)\nC. cond_wait(Line, Lock)\nD. cond_signal(Line)\nE. while Slackers >= CAPACITY\nF. while Slackers < CAPACITY\nG. Slackers++\nH. Slackers--\n
\n\n

\n

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

\n\n
\n

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

\n
\n" }, "q10": { "type": "blank", "question": "\n

\n\nGiven the previous slacklining scenario, where the slackline can\nonly support up to three people on it at a time.\u00a0\n\n

\n\n

Model this synchronization problem using POSIX threads and\nsemaphores. Assume each person is represented as a thread\nthat calls the functions above to get on the slackline, cross the\nslackline, and then get off the slackline.

\n\n

Assuming the following global variables:

\n\n
\nSemaphore Line = ?\n
\n\n

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

\n\n
\nA. sem_wait(Line)\nB. sem_post(Line)\nC. Line++\nD. Line--\nE. if Line == 0\nF. if Line > 0\n
\n\n

\n

    \n
  1. What value should the Line semaphore be initialized to? ____
  2. \n\n
  3. Select and order the lines of code above to implement the\nget_on() function. ____
  4. \n\n
  5. Select and order the lines of code above to implement the\nget_off() function. ____
  6. \n
\n

\n\n
\n

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

\n
\n" } }