{ "q01": { "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." } }, "q02": { "type": "blank", "question": "\nTwo types of non-deadlock concurrency bugs are:\n\n\n
\n\nSuppose you and your friends are going to Salsa night hosted by our beloved\nRamzi. You are willing to dance, but only after at least 2\nof your friends have started dancing.\n\n
\n\nModel this synchronization problem using POSIX threads\nand semaphores. Assume each person is represented as a\nthread that calls one of the corresponding functions below\n(you_dance() for yourself and friend_dance() for each of\nyour friends).
\n\nAssuming the following global variables:
\n\n\nsize_t MIN_FRIENDS = 2 // Minimum number of friends dancing before you will dance\nsize_t Friends = 0 // Number of friends dancing\n\nSemaphore Lock = 1\nSemaphore Dancing = 0\n\n\n
Select and order the following lines of code to implement each of the\nfunctions below:
\n\n\nA. sem_wait(Lock)\nB. sem_post(Lock)\nC. sem_wait(Dancing)\nD. sem_post(Dancing)\nE. Friends++\nF. Friends--\nG. if Friends >= MIN_FRIENDS\nH. if Friends < MIN_FRIENDS\n\n\n
\n
Put a single space between each line of code (ie. \"A B C\")).
\n