{ "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": "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" } }