{ "q08": { "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.", "livelock": "Prefer methods that utilize livelock instead of deadlock.", "holding": "Make sure we always acquire locks one at a time.", "lockfree": "Avoid locks by using atomic hardware instructions." } }, "q09": { "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" }, "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": { "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.", "lock_init": "To make a lock (binary semaphore), we initialize the semaphore to 1." } }, "q03": { "type": "blank", "question": "\n\nModify the producer / consumer queue we implemented last week to utilize\nsemaphores instead of locks and condition variables:\n\n\n\n
\nconst size_t QUEUE_MAX = 64;\n\ntemplate\n" }, "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\nclass Queue {\nprivate:\n std::queue data;\n T sentinel;\n sem_t mutex;\n sem_t full;\n sem_t empty;\n\npublic:\n Queue(T s) : sentinel(s) {\n sem_init(&mutex, 0, ____); // 1\n sem_init(&full , 0, ____); // 2\n sem_init(&empty, 0, ____); // 3\n }\n\n T pop() {\n ____; // 4\n ____; // 5\n T value = data.front();\n if (value != sentinel) {\n data.pop();\n }\n ____; // 6\n\n if (value != sentinel) {\n ____; // 7\n } else {\n ____; // 8\n }\n return value;\n }\n \n void push(const T &value) {\n ____; // 9\n ____; // 10\n data.push(value);\n ____; // 11\n ____; // 12\n }\n \n};\n