{ "q1": { "type": "blank", "question": "\n\n\nTo take advantage of modern CPUs with multiple cores, application\ndevelopers must ____ their ____ programs into separate streams of execution\ncalled ____. Each of these streams of execution co-exist within the same\n____, which means they share the same address space and thus can access the\nsame data. One common use of threads is to ____ I/O with other activities\nwithin 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.", "address": "All threads within a process share the same code, data, and heap, but not stack.", "onethread": "Only one thread per process is allowed to be executed at a time.", "main": "Every process has at least one thread.", "unlimited": "A process can have an unlimited number of threads." } }, "q3": { "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 the ____ function to start a thread and the ____\nfunction to wait for one to finish.\n\nTo guard a critical section of code, we can use a ____ from the POSIX\nthreads library as follows:\n\n\n\n
\npthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;\n____(&lock); // 3\nx = x + 1; // Critical section\n____(&lock); // 4\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;\npthread_cond_t cond = PTHREAD_COND_INITIALIZER;\npthread_mutex_lock(&lock);\nwhile (ready == 0)\n ____(&cond, &lock); // 6\npthread_mutex_unlock(&lock);\n\n\n\n\nTo perform the actual signaling, we would put the following code in\nanother thread:\n\n\n\n
\npthread_mutex_lock(&lock);\nready = 1;\n____(&cond); // 7\npthread_mutex_unlock(&lock);\n\n" }, "q4": { "type": "order", "question": "\n\n\nMatch the following terms with the following definitions (pick the terms in\norder):\n\n\n\n