{ "q1": { "type": "multiple", "question": "\n\n\nWhich of the following statements regarding threads,\nprocesses, and events are true (select all that apply)?\n\n\n", "responses": { "threads_resources": "Threads require less resources than processes.", "threads_shared": "Threads can communicate with each other using shared memory.", "threads_cleanup": "Threads provide automatic resource cleanup on exit.", "threads_parallel": "Threads can readily take advantage of parallel resources such as multiple CPU cores.", "events_overhead": "Event-based I/O can be used to provide low overhead concurrency.", "events_sync": "Event-based I/O can alleviate the need for explicit synchronization primitives.", "events_parallel": "Event-based I/O can readily take advantage of parallel resources such as multiple CPU cores.", "events_blocking": "Event-based I/O prefers blocking or long running operations." } }, "q2": { "type": "multiple", "question": "\n\n\nWhich of the following statements regarding synchronization and\ndeadlock are true (select all that apply)?\n\n\n", "responses": { "monitor_mutex": "Monitors typically use mutexes and condition variables to provide safe concurrent access to data structures.", "monitor_semaphore": "Monitors cannot be implemented using semaphores to provide safe concurrent access to data structures.", "mutex_deadlock": "The use of mutexes helps prevents deadlock.", "mutex_race": "The use of mutexes helps prevents race conditions.", "mutex_cond": "You can use a mutex without a condition variable.", "cond_deadlock": "The use of condition variables helps avoid deadlock.", "cond_wait": "The use of condition variables helps avoid busy waiting.", "cond_mutex": "You can use a condition variable without a mutex.", "semaphore_deadlock": "The use of semaphores helps prevents deadlock.", "semaphore_racewait": "The use of semaphores helps prevents race conditions and busy waiting." } }, "q3": { "type": "blank", "question": "\n

Suppose two students are meeting each other at the DPAC to see a movie:

\n\n

\n

\n

\n\n

Model this synchronization problem using POSIX threads and\nsemaphores. Assume each person is represented as a thread that\ncalls one of the corresponding functions below (student_A() for\nthe first student and student_B() for the second student).

\n\n

Assuming the following global variables:

\n\n
\nSemaphore StudentA = ____   # 1. Initial Student A semaphore value \nSemaphore StudentB = ____   # 2. Initial Student B semaphore value\n
\n\n

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

\n\n
\nA. sem_wait(StudentA)\nB. sem_post(StudentA)\nC. sem_wait(StudentB)\nD. sem_post(StudentB)\nE. StudentA++\nF. StudentB++\nG. enter_dpac()   # Student goes into DPAC\n
\n\n

3. Select and order the lines of code above to implement the\nstudent_A() function. ____

\n\n

4. Select and order the lines of code above to implement the\nstudent_B() function. ____

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

Suppose a group of NUM_STUDENTS students are meeting each other at the\nDPAC to see a movie:

\n\n

\n

\n

\n\n

Model this synchronization problem using POSIX threads,\nmutexes, and condition variables. Assume each person is\nrepresented as a thread that calls the corresponding student()\nfunction below.

\n\n

Assuming the following global variables:

\n\n
\nsize_t NUM_STUDENTS = 10   # Number of students going to movies\nsize_t Arrived      = 0    # Number of students who have arrived at theater\n\nMutex Lock\nCond  Waiting\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(Waiting, Lock)\nD. cond_signal(Waiting)\nE. while (Arrived < NUM_FRIENDS)\nF. while (Arrived > 0)\nG. if (Arrived < NUM_FRIENDS)\nH. if (Arrived > 0)\nI. Arrived++\nJ. Arrived--\nK. enter_dpac()   # Student goes into DPAC\n
\n\n

1. Select and order the lines of code above to implement the\nstudent() function. ____

\n" } }