{ "q1": { "type": "blank", "question": "\n\n\nIn a ____ program, there is more than one point of execution. Each ____ in\nthe process is a separate stream of execution, but still shares the same\naddress space and thus can access the same data.\n\n\n" }, "q3": { "type": "blank", "question": "\n\n\nTo take advantage of modern CPUs with multiple cores, application\ndevelopers must ____ their ____ programs such that multiple threads do work\non different CPUs simultaneously. One common use of threads is to ____ I/O\nwith other activities within a program.\n\n\n" }, "q2": { "type": "multiple", "question": "\n\n\nWhich of the following are true statements about threads (choose all that apply)?\n\n\n", "responses": { "registers": "Threads share the same set of registers and program counters.", "tcb": "The state of each thread is stored in a thread control block.", "onethread": "Only one thread per process is allowed to be executed at a time.", "address": "All threads within a process share the same code, data, and heap, but not stack." } }, "q5": { "type": "single", "question": "\n\n\nWhat is the problem with the code in Figure 26.6?\n\n\n", "responses": { "misspelled": "The code has misspellings (Pthread_create instead of pthread_create).", "deadlock": "There is a deadlock because two threads are accessing the same variable.", "nullargs": "The threads are passed NULL arguments.", "racecondition": "There is a race condition because the results depend on the timing execution of the code." } }, "q4": { "type": "blank", "question": "\n\n\nWith processes, we use fork to create a new process, and\nwait to wait for the process to finish. With POSIX threads, we\nuse ____ to start a thread and ____ to wait for one to\nfinish.\n\nTo guard a critical section of code, we can use the POSIX threads library\nto utilize a lock as follows:\n\n\n\n
\n____ lock = ____; // 3 & 4\n____(&lock); // 5\nx = x + 1; // Critical section\n____(&lock); // 6\n\n\n\n\nIf we need some sort of signaling between threads, we can use a ____ in the\nfollowing format:\n\n\n\n
\npthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;\n____ cond = ____; // 8 & 9\npthread_mutex_lock(&lock);\n while (ready == 0)\n ____(&cond, &lock); // 10\npthread_mutex_unlock(&lock);\n\n\n\n\nTo perform the actual signalling, we would the the following code in\nanother thread:\n\n\n\n
\npthread_mutex_lock(&lock);\nready = 1;\n____(&cond); // 11\npthread_mutex_unlock(&lock);\n\n" }, "q7": { "type": "order", "question": "\n\n\nMatch the following terms with the following definitions (pick the terms in\norder):\n\n\n\n