Deck 7: Synchronization Examples
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/57
Play
Full screen (f)
Deck 7: Synchronization Examples
1
A notify( ) operation in Java monitors
A) removes a process from the wait set and puts it in the entry set.
B) removes a process from the entry set and puts it in the wait set.
C) removes a process from the entry set and provides the lock for the object to that process.
D) removes a process from the wait set and provides the lock for the object to that process.
A) removes a process from the wait set and puts it in the entry set.
B) removes a process from the entry set and puts it in the wait set.
C) removes a process from the entry set and provides the lock for the object to that process.
D) removes a process from the wait set and provides the lock for the object to that process.
A
2
A key difference between Reentrant locks and JAVA monitor's synchronized statements is that
A) there is a possibility of deadlock when using a monitor while deadlock cannot occur when using reentrant locks.
B) a reentrant lock favors granting the lock to the longest-waiting thread while there is no specification for the order in which threads in the wait set for an object lock.
C) multiple processes may own a reentrant lock at the same time while at most one process may execute inside a synchronized method at any time.
D) at most one process may own a reentrant lock, while multiple processes may execute inside a synchronized method at any time.
A) there is a possibility of deadlock when using a monitor while deadlock cannot occur when using reentrant locks.
B) a reentrant lock favors granting the lock to the longest-waiting thread while there is no specification for the order in which threads in the wait set for an object lock.
C) multiple processes may own a reentrant lock at the same time while at most one process may execute inside a synchronized method at any time.
D) at most one process may own a reentrant lock, while multiple processes may execute inside a synchronized method at any time.
B
3
In an asymmetric solution for the dining philosophers problem, deadlock is avoided, because
A) there is no contention for acquiring chopsticks.
B) neighboring philosophers will never get hungry at the same time.
C) any neighboring philosophers would have already acquired one of their chopsticks before attempting to acquire the shared chopstick.
D) a philosopher will release a chopstick in case she is unable to acquire the other chopstick.
A) there is no contention for acquiring chopsticks.
B) neighboring philosophers will never get hungry at the same time.
C) any neighboring philosophers would have already acquired one of their chopsticks before attempting to acquire the shared chopstick.
D) a philosopher will release a chopstick in case she is unable to acquire the other chopstick.
C
4
Which of the following is true about the two versions of readers-writers problem?
A) In the first readers-writers problem, a writer may starve if a continuous series of readers arrive before the earlier readers exit their critical section.
B) In the second readers-writers problem, a reader may starve if a continuous series of readers arrive before the earlier readers exit their critical section.
C) In the first readers-writers problem, a writer may starve if a continuous series of writers arrive before the earlier writers exit their critical section.
D) In the second readers-writers problem, a writer may starve if a continuous series of readers arrive before the earlier readers exit their critical section.
A) In the first readers-writers problem, a writer may starve if a continuous series of readers arrive before the earlier readers exit their critical section.
B) In the second readers-writers problem, a reader may starve if a continuous series of readers arrive before the earlier readers exit their critical section.
C) In the first readers-writers problem, a writer may starve if a continuous series of writers arrive before the earlier writers exit their critical section.
D) In the second readers-writers problem, a writer may starve if a continuous series of readers arrive before the earlier readers exit their critical section.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
5
POSIX named semaphores
A) can easily be used by multiple unrelated processes.
B) can be initialized during creation time.
C) uses sem_wait( ) and sem_post( ) to acquire and release a semaphore respectively.
D) All of the above.
A) can easily be used by multiple unrelated processes.
B) can be initialized during creation time.
C) uses sem_wait( ) and sem_post( ) to acquire and release a semaphore respectively.
D) All of the above.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
6
In a single processor system running Windows, when the kernel accesses a global resource, it
A) uses spinlocks.
B) masks all interrupts.
C) uses a dispatcher object.
D) atomic integers.
A) uses spinlocks.
B) masks all interrupts.
C) uses a dispatcher object.
D) atomic integers.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
7
When the state for a dispatcher object moves to signaled, the Windows kernel
A) moves all threads waiting on that object to ready state if the dispatcher object is a mutex object.
B) moves a fixed number of threads (possibly greater than one) waiting on that object to ready state if the dispatcher object is a mutex object.
C) moves all threads waiting on that object to ready state if the dispatcher object is an event object.
D) moves a fixed number of threads (possibly greater than one) waiting on that object to ready state if the dispatcher object is an event object.
A) moves all threads waiting on that object to ready state if the dispatcher object is a mutex object.
B) moves a fixed number of threads (possibly greater than one) waiting on that object to ready state if the dispatcher object is a mutex object.
C) moves all threads waiting on that object to ready state if the dispatcher object is an event object.
D) moves a fixed number of threads (possibly greater than one) waiting on that object to ready state if the dispatcher object is an event object.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
8
A reader-writer lock is useful when
A) there are a significantly large number of processes attempting to enter a critical section.
B) there are a significantly large number of consumer processes attempting to read data from a bounded buffer.
C) there are a significantly small number of reader processes attempting to read in the critical section.
D) there are a significantly large number of reader processes attempting to read in the critical section.
A) there are a significantly large number of processes attempting to enter a critical section.
B) there are a significantly large number of consumer processes attempting to read data from a bounded buffer.
C) there are a significantly small number of reader processes attempting to read in the critical section.
D) there are a significantly large number of reader processes attempting to read in the critical section.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
9
In the monitor solution for dining-philosophers problem (Figure 7.7), a philosopher may start eating
A) at the end of the pickup( ) function before exiting the function.
B) in the beginning of the putdown( ) function
C) after exiting the pickup( ) function and before entering the putdown( ) function.
D) All of the above.
A) at the end of the pickup( ) function before exiting the function.
B) in the beginning of the putdown( ) function
C) after exiting the pickup( ) function and before entering the putdown( ) function.
D) All of the above.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
10
In JAVA, when a thread calls wait( ) inside a synchronized method,
A) the thread releases the object lock and continues its execution.
B) the thread releases the object lock, blocks and is put in the entry set.
C) the thread releases the object lock, blocks and is put in the wait set.
D) the thread continues its execution without releasing the object lock.
A) the thread releases the object lock and continues its execution.
B) the thread releases the object lock, blocks and is put in the entry set.
C) the thread releases the object lock, blocks and is put in the wait set.
D) the thread continues its execution without releasing the object lock.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
11
Emergence of multicore systems has put greater emphasis on developing novel techniques for concurrency problems, because
A) some fundamentally new concurrency problems have arisen that cannot be solved using traditional techniques such as mutex locks, semaphores, and monitors.
B) race conditions are much more difficult to solve in multicore systems.
C) deadlocks are much more difficult to prevent or avoid in multicore systems.
C) with increased number of processing cores, there is an increased risk of race conditions and deadlocks.
A) some fundamentally new concurrency problems have arisen that cannot be solved using traditional techniques such as mutex locks, semaphores, and monitors.
B) race conditions are much more difficult to solve in multicore systems.
C) deadlocks are much more difficult to prevent or avoid in multicore systems.
C) with increased number of processing cores, there is an increased risk of race conditions and deadlocks.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
12
A critical-section object in Windows
A) is particularly efficient when there is lots of contention for the object.
B) completely avoids kernel intervention.
C) uses spinlocks on single processor systems.
D) None of the above.
A) is particularly efficient when there is lots of contention for the object.
B) completely avoids kernel intervention.
C) uses spinlocks on single processor systems.
D) None of the above.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
13
Alternate approaches such as transactional memory or OpenMP are useful, because
A) some race condition problems that cannot be solved using synchronization mechanisms such as mutex locks and semaphores can be solved using these alternate approaches.
B) these approaches scale much better than synchronization mechanisms such as mutex locks and semaphores as the number of threads increases.
C) developers do not need to identify race conditions when using these approaches.
D) All of the above.
A) some race condition problems that cannot be solved using synchronization mechanisms such as mutex locks and semaphores can be solved using these alternate approaches.
B) these approaches scale much better than synchronization mechanisms such as mutex locks and semaphores as the number of threads increases.
C) developers do not need to identify race conditions when using these approaches.
D) All of the above.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
14
Atomic integers in Linux are useful when
A) several variables are involved in a race condition.
B) a single process access several variable involved in a race condition.
C) an integer variable needs to be updated.
D) All of the above.
A) several variables are involved in a race condition.
B) a single process access several variable involved in a race condition.
C) an integer variable needs to be updated.
D) All of the above.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
15
A thread using POSIX condition variables, a thread
A) must lock the associated mutex lock before calling pthread_cond_wait( ) and unlock it after calling pthread_cond_signal( ).
B) must lock the associated mutex lock before calling pthread_cond_wait( ), but doesn't need to unlock it after calling pthread_cond_signal( ).
C) doesn't need to lock the associated mutex lock before calling pthread_cond_wait( ), but must unlock it after calling pthread_cond_signal( ).
D) doesn't need to lock the associated mutex lock before calling pthread_cond_wait( ) and doesn't need to unlock it after calling pthread_cond_signal( ).
A) must lock the associated mutex lock before calling pthread_cond_wait( ) and unlock it after calling pthread_cond_signal( ).
B) must lock the associated mutex lock before calling pthread_cond_wait( ), but doesn't need to unlock it after calling pthread_cond_signal( ).
C) doesn't need to lock the associated mutex lock before calling pthread_cond_wait( ), but must unlock it after calling pthread_cond_signal( ).
D) doesn't need to lock the associated mutex lock before calling pthread_cond_wait( ) and doesn't need to unlock it after calling pthread_cond_signal( ).
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
16
In the solution for bounded buffer problem using JAVA monitors (Figure 7.9), functions insert( ) and remove( ) are synchronized to ensure that
A) a thread may insert an item and different thread may remove an item from a different location in the buffer simultaneously.
B) at most one thread may enter or remove an item at any time.
C) at most one thread may enter an item at any time, but multiple threads may remove items from different locations at the same time.
D) multiple thread may enter items at different locations at the same time, but at most one thread may remove an item at the same time.
A) a thread may insert an item and different thread may remove an item from a different location in the buffer simultaneously.
B) at most one thread may enter or remove an item at any time.
C) at most one thread may enter an item at any time, but multiple threads may remove items from different locations at the same time.
D) multiple thread may enter items at different locations at the same time, but at most one thread may remove an item at the same time.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
17
A(n) ___________ is a sequence of read-write operations that are atomic.
A) atomic integer
B) semaphore
C) memory transaction
D) mutex lock
A) atomic integer
B) semaphore
C) memory transaction
D) mutex lock
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
18
Which of the following statements is not true about spinlocks in Linux?
A) Spinlocks cannot be used on single processor machines.
B) A thread may disable kernel preemption on Symmetric Multi Processing machines instead of acquiring spinlocks.
C) A thread that acquires a spinlock cannot acquire the same lock a second time without first releasing the lock.
D) The Linux kernel is designed so that the spinlock is held only for only short durations.
A) Spinlocks cannot be used on single processor machines.
B) A thread may disable kernel preemption on Symmetric Multi Processing machines instead of acquiring spinlocks.
C) A thread that acquires a spinlock cannot acquire the same lock a second time without first releasing the lock.
D) The Linux kernel is designed so that the spinlock is held only for only short durations.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
19
In the structure of the producer process shown in Figure 7.1, what would be a possible outcome if wait(empty) is replaced with signal(empty) and signal(full) is replaced with wait(full)?
A) Producer will remain blocked after adding an item in the buffer.
B) Consumer will remain blocked after taking out an item from the buffer.
C) Producer and consumer may access the buffer at the same time.
D) All of the above.
A) Producer will remain blocked after adding an item in the buffer.
B) Consumer will remain blocked after taking out an item from the buffer.
C) Producer and consumer may access the buffer at the same time.
D) All of the above.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
20
The signal( ) operation in the example using JAVA condition variables ensures that the thread with the thread number turn
A) that is blocked on await( ) is unblocked.
B) that may be blocked on await( ) is unblocked.
C) does not block on await( ) even if hasn't yet called this function.
D) blocks on await( ) if it hasn't yet called this function.
A) that is blocked on await( ) is unblocked.
B) that may be blocked on await( ) is unblocked.
C) does not block on await( ) even if hasn't yet called this function.
D) blocks on await( ) if it hasn't yet called this function.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
21
In JAVA monitors, when a thread is placed in the entry set, is that thread guaranteed to own the object lock some time in future.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
22
Explain the relationship between the state of a dispatcher object and the state of a thread in Windows.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
23
Describe the mechanisms used for synchronization in Windows kernel in single and multiprocessor systems. Explain why Windows uses different mechanisms for the two systems.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
24
Explain what will happen if a process A locks the associated mutex before calling pthread cond wait( ), but another process B does not lock the associated mutex before call pthread_cond_signal( ).
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
25
A difference between software transactional memory (STM) and hardware transactional memory (HTM) is that
A) HTM uses cache hierarchy and cache coherency protocols while STM uses software implementation in addition to the cache hierarchy and cache coherency protocols.
B) STM requires no special code instrumentation and thus has less overhead than HTM.
C) In HTM, code is inserted by a compiler, while in STM, user enters the appropriate code.
D) HTM requires existing cache hierarchies and cache coherency protocols be modified, while STM does not.
A) HTM uses cache hierarchy and cache coherency protocols while STM uses software implementation in addition to the cache hierarchy and cache coherency protocols.
B) STM requires no special code instrumentation and thus has less overhead than HTM.
C) In HTM, code is inserted by a compiler, while in STM, user enters the appropriate code.
D) HTM requires existing cache hierarchies and cache coherency protocols be modified, while STM does not.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
26
What is the difference between software transactional memory and hardware transactional memory?
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
27
An advantage of using transactional memory is that
A) the atomicity is guaranteed by the transactional memory system.
B) there is no possibility of deadlocks.
C) the transactional memory system can identify which statements in atomic blocks can be executed concurrently. D. All of the above.
A) the atomicity is guaranteed by the transactional memory system.
B) there is no possibility of deadlocks.
C) the transactional memory system can identify which statements in atomic blocks can be executed concurrently. D. All of the above.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
28
In functional programming languages,
A) race conditions cannot occur.
B) there is no need to maintain program state.
C) deadlocks cannot occur.
D) All of the above.
A) race conditions cannot occur.
B) there is no need to maintain program state.
C) deadlocks cannot occur.
D) All of the above.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
29
Does nested critical sections in OpenMP provide any utility? Explain why.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
30
Describe how a critical-section object functions.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
31
Explain the difference between the first readers-writers problem and the second readers--writers problem.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
32
Explain the role of the variable preempt_count in the Linux kernel.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
33
Describe a scenario when using a reader-writer lock is more appropriate than another synchronization tool such as a semaphore.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
34
Explain how can a POSIX unnamed semaphore be shared between multiple processes.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
35
In the solution for dining philosophers problem using monitors, provide a scenario in which a philosopher may starve to death.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
36
Explain the key limitation of wait( ) and notify( ) operations of Java monitors that Java condition variables remedy.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
37
Describe the dining-philosophers problem and how it relates to operating systems.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
38
Critical-section compiler directive in OpenMP is generally considered easier to use than standard mutex locks, because
A) management of entry and exit code is managed by OpenMP library reducing the possibility of programming errors.
B) programmers don't need to worry about race conditions.
C) a thread cannot block inside a critical section.
D) deadlock cannot occur.
A) management of entry and exit code is managed by OpenMP library reducing the possibility of programming errors.
B) programmers don't need to worry about race conditions.
C) a thread cannot block inside a critical section.
D) deadlock cannot occur.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
39
Explain how Linux manages race conditions on single-processor systems such as embedded devices.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
40
The solution for bounded buffer problem provided in
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
41
In Windows, a thread may get preempted while holding a spinlock.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
42
Allowing at most four philosophers to sit simultaneously prevents deadlock.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
43
To lock the kernel on a single processor machine in Linux, kernel preemption is disabled.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
44
With reentrant locks, programming construct try and finally is used to ensure that unlock( ) is called even when an exception occurs in the critical section.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
45
A reader-writer lock gives preference to writer processes in the readers-writers problem.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
46
Transactional memory may particularly be useful for multicore systems.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
47
POSIX unnamed semaphores can be shared either only by threads with in a single process, or between processes.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
48
A critical section object in the user mode needs kernel intervention to ensure mutual exclusion.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
49
Dispatcher objects in Windows are used for synchronization outside the kernel.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
50
A solution to the readers-writers problem that avoids starvation and allows some concurrency among readers is not possible.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
51
In JAVA, calling a synchronized method always blocks the calling thread.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
52
Each critical section must be assigned a different name in OpenMP.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
53
A call to pthread_cond_signal() (used by POSIX threads, called Pthread) releases the associated mutex lock.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
54
Semaphores in JAVA can be initialized to a negative value.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
55
If a thread has the ownership of a Reentrant lock, it will block forever if it calls lock( ) before calling unlock( ).
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
56
Dining philosophers problem is important because it represents a class of problems where multiple processes need to share multiple resources.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck
57
JAVA provides support for both named and unnamed condition variables.
Unlock Deck
Unlock for access to all 57 flashcards in this deck.
Unlock Deck
k this deck