Quiz 7 APUE11
When the default action initialed by a thread is to terminate the process of this thread, what is expected?
A signal sent to a thread will terminate the entire process.
___ is a synchronization mechanism that can be used to coordinate multiple threads working in parallel. This allows each thread to wait until all cooperating threads have reached the same point, and then continue executing from there.
Barrier
Which of the following items is shared by all thread in a process?
File descriptors
When a thread is terminated, a thread can arrange for a function to be called when it exits. Which of the following statement is not correct?
The process runs this function for the thread being terminated.
When multiple threads of control share the same memory (a shared variable), one needs to make sure that each thread sees a consistent view of its data. Which of the following statements is not correct? Select one best answer.
While a thread reads a variable, there is no consistency problem.
pthread_join function acts as ___ to allow one thread to wait until another thread exits.
barrier
A ___ is basically a lock that a thread does set (lock) before accessing a shared resource and release (unlock) when we're done.
mutex
Spin locks are useful when used in a(n) ___ kernel: besides providing a mutual exclusion mechanism, they block interrupts so an interrupt handler can't deadlock the system by trying to acquire a spin lock that is already locked.
nonpreemptive
Spin locks are useful when running in real-time scheduling class that doesn't allow ____.
preemption
A thread can arrange for functions to be called when it exits, similar to the way that the atexit function.
pthread_cleanup_push
What is a thread primitive, corresponding to fork for process.
pthread_create
Which of the following functions is used to create a thread?
pthread_create
If a thread knows that no thread cares about its return value, then which of the following functions does it call to indicate that resources associated with it can be released on termination?
pthread_detach
Which of the following functions is used by a thread to terminate itself?
pthread_exit
What is a thread primitive, corresponding to waitpid for process.
pthread_join
Which of the following functions is used to wait for a thread or threads to terminate?
pthread_join
Consider the following statements for a lock in thread programming. pthread_mutex_t MutexLock; pthread_mutex_init(&MutexLock, NULL); Which of the following statement will lock the mutex called MutexLock?
pthread_mutex_lock(&MutexLock);
Which of the following functions is used by a thread to obtain its ID?
pthread_self
Consider the following function to be run by a thread. void *PrintHello(void *threadid) { . . . } pthread_t tid; int rc; Which of the following statement is correct to create a thread that executes a function called PrintHello?
rc = pthread_create(&tid, NULL, PrintHello, (void *)1);
___ is like a mutex, except that instead of blocking a process by sleeping, the process is blocked by busy-waiting until the lock can be acquired.
spin-lock
Spin locks are often used as low-level primitives to implement other types of locks, and can be implemented efficiently using ___ instruction.
test-and-set
If any thread within a process calls exit, _Exit, or _exit, then what is expected?
the entire process (with all of its threads) terminates.