Explanation:The three requirements are Mutual Exclusion, Progress, and Bounded Waiting. Strict FIFO is not a requirement, though starvation must be avoided.
Incorrect! Try again.
13Mutual Exclusion implies that:
A.Multiple threads can be in their critical sections simultaneously if they are reading.
B.If a thread is executing in its critical section, no other thread can be executing in their corresponding critical section.
C.Threads must take turns strictly.
D.All threads must share the same priority.
Correct Answer: If a thread is executing in its critical section, no other thread can be executing in their corresponding critical section.
Explanation:Mutual exclusion ensures that only one thread accesses the critical resource at a time.
Incorrect! Try again.
14What is a Mutex?
A.A mechanism to enforce First-Come-First-Serve scheduling.
B.A synchronization primitive used to enforce mutual exclusion.
C.A type of shared memory segment.
D.A function to create threads.
Correct Answer: A synchronization primitive used to enforce mutual exclusion.
Explanation:Mutex stands for Mutual Exclusion object. It acts as a lock to protect critical sections.
Incorrect! Try again.
15What function initializes a POSIX mutex?
A.pthread_mutex_create()
B.pthread_mutex_init()
C.pthread_mutex_start()
D.pthread_mutex_alloc()
Correct Answer: pthread_mutex_init()
Explanation:pthread_mutex_init() is used to initialize a mutex, either with default attributes or specific ones.
Incorrect! Try again.
16If a thread attempts to lock a mutex that is already locked by another thread using pthread_mutex_lock, what happens?
A.The calling thread returns an error immediately.
B.The calling thread terminates.
C.The calling thread blocks (waits) until the mutex becomes available.
D.The mutex is forcibly unlocked.
Correct Answer: The calling thread blocks (waits) until the mutex becomes available.
Explanation:pthread_mutex_lock blocks the caller if the mutex is currently held by another thread.
Incorrect! Try again.
17Which function allows a thread to attempt to lock a mutex without blocking if it is already locked?
A.pthread_mutex_lock()
B.pthread_mutex_trylock()
C.pthread_mutex_test()
D.pthread_mutex_check()
Correct Answer: pthread_mutex_trylock()
Explanation:pthread_mutex_trylock() attempts to lock the mutex; if it is already locked, it returns immediately with an error (usually EBUSY) instead of waiting.
Incorrect! Try again.
18What is the correct sequence of operations to protect a critical section using a mutex?
Explanation:You must acquire the lock before entering the critical section and release (unlock) it immediately after leaving.
Incorrect! Try again.
19What happens if a thread forgets to call pthread_mutex_unlock after finishing the critical section?
A.The OS automatically unlocks it after a timeout.
B.Other threads waiting for that mutex will remain blocked indefinitely (Deadlock/Starvation).
C.The mutex destroys itself.
D.The program crashes immediately.
Correct Answer: Other threads waiting for that mutex will remain blocked indefinitely (Deadlock/Starvation).
Explanation:Failing to unlock a mutex prevents other threads from acquiring it, potentially leading to a deadlock or hanging the application.
Incorrect! Try again.
20In the context of semaphores, what does the variable represent?
A.A string identifier.
B.A pointer to the thread.
C.An integer value representing available resources.
D.A floating-point priority value.
Correct Answer: An integer value representing available resources.
Explanation:A semaphore acts as a counter (integer) indicating how many units of a particular resource are available.
Incorrect! Try again.
21Which header file is required for POSIX semaphores?
A.<semaphore.h>
B.<pthread.h>
C.<sem.h>
D.<sys/sem.h>
Correct Answer: <semaphore.h>
Explanation:The standard POSIX semaphore definitions are found in <semaphore.h>.
Incorrect! Try again.
22What are the two atomic operations defined on a semaphore?
A.Read and Write
B.Wait (P) and Post (V)
C.Start and Stop
D.Lock and Unlock
Correct Answer: Wait (P) and Post (V)
Explanation:Semaphores support two atomic operations: wait (historically P) to decrement and post (historically V) to increment.
Incorrect! Try again.
23If a semaphore has a value of 0, what happens when sem_wait(&S) is called?
A. becomes -1.
B. remains 0 and the calling thread proceeds.
C.The calling thread blocks until .
D.The program terminates with an error.
Correct Answer: The calling thread blocks until .
Explanation:sem_wait decrements the value. If the value is 0, it cannot decrement, so it blocks until another thread increments it via sem_post.
Incorrect! Try again.
24What does the function sem_post(&S) do?
A.Decrements by 1.
B.Increments by 1 and wakes up a waiting thread if any.
C.Sets to 0.
D.Destroys the semaphore.
Correct Answer: Increments by 1 and wakes up a waiting thread if any.
Explanation:sem_post increments the semaphore value. If other threads are blocked in sem_wait, one is effectively unblocked.
Incorrect! Try again.
25What is the primary difference between a Mutex and a Binary Semaphore?
A.There is no difference.
B.A mutex can be unlocked by any thread, while a semaphore has ownership.
C.A mutex has ownership (only the locker can unlock), while a semaphore does not.
D.Semaphores are faster than mutexes.
Correct Answer: A mutex has ownership (only the locker can unlock), while a semaphore does not.
Explanation:Mutexes imply ownership; the thread that locks it must unlock it. Semaphores are signaling mechanisms; one thread can wait and another can post.
Incorrect! Try again.
26In sem_init(sem_t *sem, int pshared, unsigned int value), what does pshared = 0 indicate?
A.The semaphore is shared between processes.
B.The semaphore is shared only between threads of the same process.
C.The semaphore value is initialized to 0.
D.The semaphore is read-only.
Correct Answer: The semaphore is shared only between threads of the same process.
Explanation:If pshared is 0, the semaphore is shared between the threads of a process. If non-zero, it is shared between processes.
Incorrect! Try again.
27Consider the Producer-Consumer problem. Which synchronization primitive is best suited to track the number of full slots in the buffer?
A.Mutex
B.Counting Semaphore
C.Spinlock
D.Binary Semaphore
Correct Answer: Counting Semaphore
Explanation:A counting semaphore represents a count of resources (items in the buffer), making it ideal for tracking full or empty slots.
Incorrect! Try again.
28What is a Deadlock in the context of multithreading?
A.When a thread finishes execution.
B.When two or more threads are waiting indefinitely for an event that can be caused only by one of the waiting threads.
C.When a thread uses too much CPU.
D.When the operating system stops a process.
Correct Answer: When two or more threads are waiting indefinitely for an event that can be caused only by one of the waiting threads.
Explanation:Deadlock creates a cycle of dependencies where no thread can proceed.
Incorrect! Try again.
29The operation on a semaphore corresponds to which POSIX function?
A.sem_wait()
B.sem_trywait()
C.sem_post()
D.sem_getvalue()
Correct Answer: sem_post()
Explanation:In Dijkstra's notation, (verhogen) stands for incrementing, which corresponds to sem_post().
Incorrect! Try again.
30Which of the following creates a thread that is 'detached' (resources released immediately upon termination)?
A.Calling pthread_detach() on the thread.
B.Calling pthread_join().
C.Creating the thread with default attributes.
D.Using sem_post().
Correct Answer: Calling pthread_detach() on the thread.
Explanation:pthread_detach() marks the thread as detached. When a detached thread terminates, its resources are automatically released back to the system.
Incorrect! Try again.
31What is the result of pthread_mutex_destroy(&mutex) if the mutex is currently locked?
A.The mutex is destroyed and the lock is released.
B.The behavior is undefined (often returns an error like EBUSY).
C.The calling thread waits until it is unlocked.
D.The mutex is reset to initial state.
Correct Answer: The behavior is undefined (often returns an error like EBUSY).
Explanation:Destroying a locked mutex (or one referenced by another thread) results in undefined behavior or an error.
Incorrect! Try again.
32In the Dining Philosophers problem, using a single mutex to protect the entire table (all forks) results in:
A.Maximum concurrency.
B.Deadlock.
C.Serialization of eating (only one philosopher eats at a time).
D.Starvation of the middle philosopher.
Correct Answer: Serialization of eating (only one philosopher eats at a time).
Explanation:A single global lock prevents simultaneous eating, essentially serializing the process and defeating the purpose of concurrency.
Incorrect! Try again.
33What is the initial value of a semaphore used to implement a Mutex (binary semaphore)?
A.
B.1
C.2
D.-1
Correct Answer: 1
Explanation:To allow one thread to enter initially, the binary semaphore must be initialized to 1. The first wait decrements it to 0 (locking it).
Incorrect! Try again.
34Which variable type is used for a POSIX thread identifier?
A.int
B.pid_t
C.pthread_t
D.thread_id
Correct Answer: pthread_t
Explanation:pthread_t is the opaque data type used to identify a thread in POSIX.
Incorrect! Try again.
35What is the output of the following pseudocode: . Thread A: . Thread B: . (Assume load/store architecture and no synchronization).
A.Always 2
B.Always 1
C.Either 1 or 2
D.Always 0
Correct Answer: Either 1 or 2
Explanation:This is a race condition. If operations overlap (Read A, Read B, Write A, Write B), the result is 1. If serialized, the result is 2.
Incorrect! Try again.
36Which synchronization tool essentially generalizes the mutex lock to allow concurrent accesses?
A.Condition Variable
B.Monitor
C.Counting Semaphore
D.Spinlock
Correct Answer: Counting Semaphore
Explanation:A counting semaphore initialized to allows threads to pass sem_wait before blocking.
Incorrect! Try again.
37Why might pthread_mutex_trylock be preferred over pthread_mutex_lock?
A.To ensure the thread never fails to get the lock.
B.To avoid blocking the thread if the lock is unavailable, allowing it to do other work.
C.It is faster to execute.
D.It automatically unlocks the mutex.
Correct Answer: To avoid blocking the thread if the lock is unavailable, allowing it to do other work.
Explanation:trylock is non-blocking, allowing the thread to perform alternative tasks or back off to prevent deadlock.
Incorrect! Try again.
38Which of the following is true about User-Level Threads (ULT) vs Kernel-Level Threads (KLT)?
A.ULTs are managed by the kernel.
B.Blocking system calls in a ULT block the entire process (if the kernel is unaware of threads).
C.KLTs are faster to create than ULTs.
D.POSIX threads are always User-Level Threads.
Correct Answer: Blocking system calls in a ULT block the entire process (if the kernel is unaware of threads).
Explanation:In pure User-Level threading (Many-to-One), the kernel sees only one process. If a thread blocks on I/O, the whole process blocks.
Incorrect! Try again.
39When passing arguments to a thread function, why is passing the address of a loop variable (e.g., &i) dangerous?
A.The compiler cannot handle pointers in threads.
B.The loop variable i may change value before the thread starts execution.
C.It consumes too much stack memory.
D.The thread ID will be invalid.
Correct Answer: The loop variable i may change value before the thread starts execution.
Explanation:Because threads run asynchronously, the main loop might increment i before the new thread reads the value at the address of i.
Incorrect! Try again.
40Which Pthread function is used to initialize a condition variable?
A.pthread_cond_init
B.pthread_cond_start
C.pthread_cv_init
D.pthread_init_cond
Correct Answer: pthread_cond_init
Explanation:pthread_cond_init is the standard POSIX function to initialize a condition variable.
Incorrect! Try again.
41What determines if an operation is atomic?
A.It takes less than 1ms to execute.
B.It executes as a single, indivisible unit without interruption.
C.It uses a mutex.
D.It is written in C.
Correct Answer: It executes as a single, indivisible unit without interruption.
Explanation:Atomicity ensures that an operation is either fully completed or not started at all from the perspective of other threads; it cannot be interrupted mid-stream.
Incorrect! Try again.
42A spinlock is a type of lock where:
A.The thread sleeps while waiting.
B.The thread repeatedly checks (busy waits) if the lock is available.
C.The thread yields the CPU immediately.
D.The lock rotates between threads.
Correct Answer: The thread repeatedly checks (busy waits) if the lock is available.
Explanation:Spinlocks use busy waiting. They are efficient for short critical sections on multiprocessor systems but waste CPU cycles.
Incorrect! Try again.
43Which Pthread function yields the processor to another thread?
Explanation:pthread_yield (often implemented as sched_yield in standard POSIX) forces the current thread to relinquish the CPU.
Incorrect! Try again.
44What is the main disadvantage of using sem_unlink()?
A.It stops the semaphore immediately.
B.It removes the name of a named semaphore, but existing references remain valid.
C.It crashes the system.
D.It resets the semaphore count.
Correct Answer: It removes the name of a named semaphore, but existing references remain valid.
Explanation:sem_unlink removes the directory entry for a named semaphore. The semaphore itself is destroyed only when the last process closes it.
Incorrect! Try again.
45In the Reader-Writer problem, a Writer requires:
A.Shared access.
B.Exclusive access to the database.
C.No access.
D.Read-only access.
Correct Answer: Exclusive access to the database.
Explanation:Writers must have exclusive access to prevent race conditions. Readers can share access with other readers.
Incorrect! Try again.
46What happens if you call pthread_join on a thread that has already been detached?
A.It joins successfully.
B.It creates a new thread.
C.It results in undefined behavior (usually an error).
D.It forces the thread to re-attach.
Correct Answer: It results in undefined behavior (usually an error).
Explanation:You cannot join a detached thread. Doing so is an error (typically EINVAL).
Incorrect! Try again.
47The pthread_attr_init function is used to:
A.Initialize a thread directly.
B.Initialize a thread attribute object with default values.
C.Start a thread.
D.Set the thread priority.
Correct Answer: Initialize a thread attribute object with default values.
Explanation:It prepares an attribute object that can later be customized (e.g., stack size, detached state) and passed to pthread_create.
Incorrect! Try again.
48Which of the following is a classic example of a synchronization problem?
A.The Hello World Problem.
B.The Traveling Salesman Problem.
C.The Bounded-Buffer (Producer-Consumer) Problem.
D.The Knapsack Problem.
Correct Answer: The Bounded-Buffer (Producer-Consumer) Problem.
Explanation:The Bounded-Buffer problem is a classic scenario used to illustrate the need for synchronization between processes producing and consuming data.
Incorrect! Try again.
49If a mutex is 'recursive', it means:
A.It calls itself.
B.The same thread can lock it multiple times without deadlocking.
C.It can be locked by multiple threads at once.
D.It is used for recursive functions only.
Correct Answer: The same thread can lock it multiple times without deadlocking.
Explanation:A recursive mutex allows the holding thread to re-acquire the lock. It maintains a lock count and must be unlocked the same number of times.
Incorrect! Try again.
50In pthread_create, if the attribute argument is NULL, what happens?
A.The thread is not created.
B.The thread is created with default attributes.
C.The thread is created as a zombie.
D.The compiler throws an error.
Correct Answer: The thread is created with default attributes.
Explanation:Passing NULL as the second argument tells the system to use the default thread attributes (joinable, default stack size, etc.).
Incorrect! Try again.
Give Feedback
Help us improve by sharing your thoughts or reporting issues.