quiz 13 unix (1)

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

[APUE11.6] Assume that you have two mutexes, A and B, that you need to lock at the same time. If all threads always lock mutex A before mutex B, ____. Deadlocks can be avoided with these two mutexes. It is still possible to have a deadlock with these two mutexes. It is still possible to have a deadlock with the mutex A. It is still possible to have a deadlock with the mutex B. None of the above is correct.

Deadlocks can be avoided with these two mutexes.

[APUE11.6] A mutex variable must be first initialized by either setting it to the constant _____ (for statically allocated mutexes only) or calling ____. pthread_mutex_t, pthread_mutex_start PTHREAD_MUTEX_INITIALIZER, pthread_mutex_init PTHREAD_MUTEX_T, pthread_mutex_init PTHREAD_MUTEX_INIT, pthread_mutex_allocate pthread_mutex_allocate, pthread_mutex_initialize

PTHREAD_MUTEX_INITIALIZER, pthread_mutex_init

[APUE11.6] The pthread_join function acts as a ____ to allow one thread to wait until another thread exits. barrier conditional variable mutex message queue reader-writer lock semaphore spinlock

barrier

[APUE11.6] The condition is the state of the work queue. We protect the condition with a mutex and evaluate the condition in a while loop. When we put a message on the work queue, we need to hold the mutex, but we don't need to hold the mutex when we signal the waiting threads. As long as it is okay for a thread to pull the message off the queue before we call a signal, we can do this after releasing the mutex. Since we check the condition in a while loop, this doesn't present a problem; a thread will wake up, find that the queue is still empty, and go back to waiting again. If the code couldn't tolerate this race, we would need to hold the mutex when we signal the threads. This is about ____ mechanism. barrier conditional variable mutex message queue reader-writer lock semaphore socket signal

conditional variable

[APUE11.6] A thread will ____ if it tries to lock the same mutex twice. allocate mutex deadlock itself free mutex first interrupt itself spin itself unlock mutex

deadlock itself

[APUE11.6] We can protect our data and ensure access by only one thread at a time by using the pthreads mutual-exclusion interfaces. A(n) ____ is basically a lock that we set (lock) before accessing a shared resource and release (unlock) when we're done. barrier conditional variable deadlock livelock message queue mutex pipe semaphore

mutex

[APUE11.6] The _____ mechanism works only if we design our threads to follow the same data-access rules. The operating system doesn't serialize access to data for us. If we allow one thread to access a shared resource without first acquiring a lock, then inconsistencies can occur even though the rest of our threads do acquire the lock before attempting to access the shared resource. asynchronization blocking mutual-exclusion nonblocking preemption resource-sharing synchronization

mutual-exclusion

[APUE11.6] A typical UNIX _____ can be thought of as having a single thread of control (that is, doing only one thing at a time). process signal semaphore socket transaction

process

[APUE11.6] If we allocate the mutex dynamically (by calling malloc, for example), then we need to call _____ before freeing the memory. pthread_mutex_destroy pthread_mutex_deallocate pthread_mutex_free pthread_mutex_exit pthread_mutex_return

pthread_mutex_destroy

[APUE11.6] To initialize a mutex with the default attributes, we set attr to NULL. To lock a mutex, we call ____. If the mutex is already locked, the calling thread will block until the mutex is unlocked. To unlock a mutex, we call ____. pthread_mutex_access, pthread_mutex_unaccess pthread_mutex_begin, pthread_mutex_end pthread_mutex_enter, pthread_mutex_exit pthread_mutex_lock, pthread_mutex_unlock pthread_mutex_start, pthread_mutex_stop

pthread_mutex_lock, pthread_mutex_unlock

[APUE11.6] One additional mutex primitive allows us to bound the time that a thread blocks when a mutex it is trying to acquire is already locked. The ____ function is equivalent to pthread_mutex_lock, but if the timeout value is reached, it will return the error code ETIMEDOUT without locking the mutex. pthread_mutex_time pthread_mutex_timelock pthread_mutex_timedlock pthread_mutex_timeset pthread_mutex_timelimit

pthread_mutex_timedlock

[APUE11.6] A reader-writer lock is initialized by calling ____. pthread_reader_writer_lock_init pthread_rw_lock_init pthread_rwlock_init pthread_readwritelock_init pthread_rdwtlock_init

pthread_rwlock_init

[APUE11.6] To lock a reader-writer lock in read mode, we call ____. pthread_rwlock_read pthread_readlock pthread_writelock pthread_rwlock_rdlock pthread_rwlock_readlock

pthread_rwlock_rdlock

[APUE11.6] Just as with mutexes, the Single UNIX Specification provides functions to lock reader-writer locks with a timeout to give applications a way to avoid blocking indefinitely while trying to acquire a reader-writer lock. One of these functions is _____. pthread_rwlock_timedrwlock pthread_rwlock_timedrdlock pthread_readlock_timed pthread_rwlock_timedreadlock pthread_rwlock_timedwrlock

pthread_rwlock_timedwrlock

[APUE11.6] To write lock a reader-writer lock, we call ____. pthread_rwlock_write pthread_readlock pthread_writelock pthread_rwlock_wrlock pthread_rwlock_writelock

pthread_rwlock_wrlock

[APUE11.6] When a reader-writer lock is ____ locked, all threads attempting to ___ are given access, but all threads attempting to write must wait until the lock is released by all threads in ____. allocate free access read update write

read

[APUE11.6] Only one thread at a time can hold a(n) ____ in write mode, but multiple threads can hold a(n) ____ in read mode at the same time. barrier conditional variable mutex message queue reader-writer lock semaphore socket signal

reader-writer lock

[APUE11.6] At user level, ____ is not as useful unless you are running in a real-time scheduling class that doesn't allow preemption. User-level threads running in a time-sharing scheduling class can be descheduled when their time quantum expires or when a thread with a higher scheduling priority becomes runnable. In these cases, if a thread is holding ____, it will be put to sleep and other threads blocked on the lock will continue waiting longer than intended. barrier conditional variable mutex message queue reader-writer lock semaphore spinlock

spinlock

[APUE11.6] Although implementations vary, reader-writer locks usually block additional readers if a lock is already held in read mode and a thread is blocked trying to acquire the lock in write mode. This prevents a constant stream of readers from ____ waiting writers. deadlocked exhausted interrupted lost sleeping starving spinning

starving

[APUE11.6] When a reader-writer lock is ____ locked, only one thread to ____ can have it while all threads attempting to read must wait until it is unlocked. allocate free access read update write

write


संबंधित स्टडी सेट्स

AP HUG Unit 1,2,3 progress checks

View Set

Bible - Poetry and wisdom section

View Set

Exam 3 OB Nursing-Ch19, 20, 21, 23, 24

View Set

Ch. 5 - Process Costing - ACCT 3202

View Set

12 - California Laws and Ethics Pertinent to Insurance

View Set