Threads and Multithreading - multicore programming, multithreading models, thread libraries, implicit threading, threading issues - Question Bank

1. Consider a scenario where Thread A holds Resource 1 and needs Resource 2, while Thread B holds Resource 2 and needs Resource 1. This is a classic example of:
A) Race condition
B) Starvation
C) Deadlock
D) Livelock
2. What is the primary difference between a thread and a process?
A) Processes have their own memory space, while threads share the memory space of their parent process.
B) Threads can only execute sequentially, while processes can run in parallel.
C) Processes are managed by user-level libraries, while threads are managed by the kernel.
D) Processes are lighter weight than threads.
3. Which of the following is a key component of the OpenMP API for implicit threading in C/C++?
A) pthread_create()
B) #pragma omp parallel for
C) new Thread()
D) go func()
4. What is a potential problem with fine-grained locking (using many locks for small sections of data)?
A) Increased complexity and potential for deadlock
B) Reduced concurrency
C) Higher memory overhead
D) Slower execution speed
5. Which synchronization primitive is suitable for managing access to a resource that can be used by a limited number of threads concurrently (e.g., a connection pool)?
A) Mutex
B) Condition Variable
C) Semaphore
D) Atomic Variable
6. In multicore programming, what is 'granularity' referring to?
A) The size of the data shared between threads
B) The level of parallelism in a program, related to the size of independent tasks
C) The number of CPU cores available
D) The complexity of the synchronization mechanisms used
7. Which threading issue involves threads repeatedly making progress but failing to reach a final goal due to continuous changes in the system state?
A) Deadlock
B) Starvation
C) Livelock
D) Race condition
8. What is the role of the 'scheduler' in a user-level threading implementation (like the many-to-one model)?
A) To manage kernel threads
B) To schedule user threads onto available kernel threads
C) To handle system calls
D) To manage memory for the process
9. Which model offers a good balance between the overhead of the many-to-one model and the potential resource consumption of the one-to-one model?
A) Many-to-one
B) One-to-one
C) Many-to-many
D) Two-level model
10. What is the main limitation of the many-to-one threading model concerning parallelism?
A) It requires too many kernel threads
B) A blocking system call by one thread blocks all threads
C) It cannot utilize multiple CPU cores effectively
D) Thread creation is too slow
11. Which of the following is a common synchronization problem that can occur if not managed carefully?
A) Buffer overflow
B) Stack overflow
C) Race condition
D) Integer overflow
12. What is a 'detached thread' in multithreading?
A) A thread that can be cancelled at any time
B) A thread whose resources are automatically reclaimed upon termination without needing to be joined
C) A thread that runs independently of the main thread
D) A thread that is currently blocked
13. In multicore programming, what does 'load balancing' refer to?
A) Distributing computational work evenly across available cores
B) Ensuring that threads access shared data sequentially
C) Minimizing the number of context switches
D) Reducing the memory usage of threads
14. Which of the following best describes a 'task' in task-based parallelism (often used in implicit threading)?
A) A single CPU instruction
B) A unit of work that can be executed independently
C) A low-level thread
D) A system call
15. What is the purpose of `pthread_join()` in POSIX threads?
A) To create a new thread
B) To allow a thread to wait for another thread to complete its execution
C) To detach a thread, allowing its resources to be reclaimed automatically
D) To set thread attributes
16. Which threading issue is characterized by a process not making progress because it is waiting for a resource held by another process that is also waiting?
A) Race condition
B) Starvation
C) Deadlock
D) Livelock
17. What is a potential issue with using a large number of kernel threads in the one-to-one model?
A) Increased risk of race conditions
B) High overhead and resource consumption
C) Difficulty in synchronization
D) Reduced parallelism
18. Which threading model is used by default in Java?
A) Many-to-one
B) One-to-one
C) Many-to-many
D) It depends on the JVM implementation and the operating system
19. In the context of POSIX Threads (pthreads), what is a common function for creating a new thread?
A) fork()
B) spawn()
C) pthread_create()
D) thread_new()
20. What is a 'spin lock'?
A) A lock that causes a thread to yield the CPU when it cannot acquire the lock
B) A lock that causes a thread to busy-wait (spin) until the lock is available
C) A lock that is automatically released after a fixed time
D) A lock that allows multiple threads to access a resource simultaneously
21. Which of the following is a mechanism to prevent race conditions?
A) Increasing thread priority
B) Using a mutex to protect critical sections
C) Allocating more memory to the process
D) Disabling interrupts
22. What is a primary goal of multicore programming?
A) To reduce the number of processes running on the system
B) To execute tasks in parallel across multiple CPU cores
C) To increase the memory footprint of applications
D) To simplify inter-process communication
23. Which type of threading abstracts thread creation and management away from the programmer, often using libraries or language features?
A) Explicit threading
B) User-level threading
C) Kernel-level threading
D) Implicit threading
24. The many-to-many model attempts to combine the benefits of which other models?
A) One-to-one and One-to-many
B) Many-to-one and One-to-one
C) One-to-one and Many-to-many
D) Many-to-one and Many-to-many
25. What is the main benefit of the one-to-one multithreading model?
A) Reduced system overhead
B) Allows concurrency even if one thread makes a blocking system call
C) Simpler thread management
D) Efficient for applications with few threads
26. Which of the following is a disadvantage of the many-to-one multithreading model?
A) High overhead for thread creation
B) A blocking system call by one thread blocks all threads
C) Requires a kernel thread for every user thread
D) Difficult to implement
27. What is a 'critical section' in multithreading?
A) A section of code that is executed only once
B) A block of code that accesses shared resources and must be protected from concurrent access
C) A region of memory allocated for thread stacks
D) The main execution path of a thread
28. Which scenario is most likely to lead to a deadlock?
A) Threads accessing independent resources
B) Threads acquiring locks in the same order
C) Threads acquiring locks in a circular wait dependency
D) Threads releasing locks promptly after use
29. In multicore programming, the challenge of ensuring that multiple threads operate on shared data without corrupting it is known as:
A) Load balancing
B) Synchronization
C) Task decomposition
D) Parallelism
30. What is the primary purpose of a thread pool?
A) To manage the creation and destruction of threads dynamically
B) To execute tasks sequentially on a single thread
C) To provide a fixed set of worker threads ready to execute tasks
D) To synchronize access to shared data
31. Which programming paradigm is often associated with implicit threading, simplifying concurrent programming?
A) Object-Oriented Programming
B) Procedural Programming
C) Functional Programming
D) Imperative Programming
32. What is starvation in multithreading?
A) A situation where a thread consumes excessive CPU resources
B) A condition where a thread is perpetually denied access to necessary resources
C) The termination of a thread due to an unhandled exception
D) A state where a thread is blocked indefinitely
33. Which of the following is an example of a common threading issue related to resource contention?
A) Stack overflow
B) Memory leak
C) Deadlock
D) Buffer overflow
34. What is thread-local storage (TLS)?
A) A mechanism to share data between all threads in a process
B) A way to allocate memory for threads on the heap
C) A technique where each thread has its own copy of a variable
D) A method for synchronizing thread access to global variables
35. Which type of threading allows a large number of user threads to be mapped onto a smaller or equal number of kernel threads?
A) One-to-one model
B) Many-to-one model
C) Many-to-many model
D) Two-level model
36. Which of the following is a benefit of the one-to-one multithreading model?
A) Low overhead for thread creation
B) Allows one thread to block without blocking others
C) Simplified thread management
D) Reduced kernel complexity
37. In the many-to-one multithreading model, what happens if one user thread performs a blocking system call?
A) Only that thread is blocked, and others can continue
B) The entire process is blocked, preventing other threads from executing
C) The kernel thread associated with the blocked user thread is rescheduled
D) The system automatically switches to a different user thread
38. What is the purpose of a condition variable?
A) To provide exclusive access to a shared resource
B) To signal and wait for specific conditions to be met
C) To manage a pool of reusable threads
D) To prevent race conditions
39. A semaphore initialized to 1 can function similarly to which other synchronization primitive?
A) Mutex
B) Condition variable
C) Reader-writer lock
D) Spinlock
40. Which synchronization primitive is often used to ensure that only one thread can access a critical section of code at a time?
A) Semaphore
B) Condition variable
C) Mutex (Mutual Exclusion)
D) Atomic variable
41. What is a deadlock in the context of multithreading?
A) A situation where a thread is repeatedly denied CPU time
B) A state where two or more threads are blocked forever, each waiting for the other to release a resource
C) A condition where a thread cannot make progress because it is waiting for an event that will never occur
D) An error in thread scheduling leading to termination
42. Which threading issue arises when multiple threads access and modify shared data concurrently, leading to unpredictable results?
A) Deadlock
B) Starvation
C) Race condition
D) Livelock
43. What is a common technique used in implicit threading to manage threads?
A) Manual thread pool management
B) Thread-local storage
C) Thread pools and task-based parallelism
D) Explicitly calling thread creation functions
44. Which of the following is a characteristic of implicit threading?
A) Developers explicitly create and manage each thread using an API
B) The creation and management of threads are hidden from the developer
C) Threads are always mapped one-to-one with kernel threads
D) It relies heavily on manual synchronization
45. What is the primary function of a thread library?
A) To manage memory allocation for the entire system
B) To provide an API for creating, managing, and synchronizing threads
C) To handle process scheduling and dispatching
D) To facilitate inter-process communication
46. Which thread library operates entirely in user space and does not require kernel support for thread management?
A) POSIX Threads (pthreads)
B) Java Threads
C) Windows Threads
D) Thread Library (like GNU Portable Threads)
47. In the one-to-one multithreading model, what is a potential drawback?
A) A blocking system call in one thread blocks the entire process
B) High overhead due to creating a kernel thread for each user thread
C) Difficulty in creating a large number of threads
D) Limited parallelism if the number of kernel threads is less than the number of cores
48. Which multithreading model maps many user-level threads to one or more kernel-level threads?
A) One-to-one model
B) Many-to-one model
C) Many-to-many model
D) One-to-many model
49. In the context of multicore programming, what is a common challenge faced by developers?
A) Ensuring sequential execution of tasks
B) Efficiently distributing work across multiple cores
C) Minimizing the need for synchronization primitives
D) Reducing the number of available registers
50. Which of the following best describes a thread?
A) An independent process with its own memory space
B) A lightweight process sharing resources with other threads in the same process
C) A unit of execution scheduled independently by the operating system
D) A mechanism for inter-process communication