{ "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\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\nAssuming 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\nAssuming 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
Put a single space between each line of code (ie. \"A B C\")).
\n