WorksheetsCSF20303_Chap 4 : Multithreaded Programming
Total questions: 100
Worksheet time: 55mins
Which scenario best demonstrates applying thread responsiveness to improve user experience?
Adding more RAM to increase process speed
Splitting a UI program so UI updates continue while data loads
Rebooting the OS to reset blocked processes
Combining all program functions into one loop
A developer wants to redesign an application so that tasks like spell checking and fetching data can occur simultaneously. Which OS concept should be applied?
Virtual memory
Multithreading
Device drivers
Paging
Given a system with heavy data-splitting needs, which type of parallelism is most applicable?
Task parallelism
Data parallelism
Virtual parallelism
Logical parallelism
A programmer needs to distribute unique tasks across multiple cores. Which type of parallelism should be applied?
Data parallelism
Serial execution
Task parallelism
Cooperative memory
A process requires faster context switching with minimal overhead. Which execution model should be applied?
Process creation model
Heavyweight scheduling
Multithreading
Distributed OS
A CPU with a single core needs to run multiple threads that appear simultaneous. Which OS concept enables this?
True parallelism
Hardware pipelining
Concurrency
Multi-booting
Applying Amdahl’s Law, increasing the number of cores gives diminishing returns because:
Parallel tasks consume more RAM
Serial portions limit total speedup
Cores communicate too slowly
OS prevents scaling beyond four cores
A programmer needs every new user-level thread to map to a kernel thread. Which model should be chosen?
Many-to-One
One-to-One
Many-to-Many
Hybrid caching
When designing an application requiring thousands of threads but limited kernel overhead, which model is most applicable?
One-to-one
Many-to-one
Many-to-many
Single-threaded
A thread library that must function when programmer has no control over thread creation should use:
Local variables
Static memory
Thread-local storage
Shared memory pages
To allow different strategies for running tasks without recreating threads, which technique should be applied?
Fork-join execution
Thread pools
Synchronous signals
TLB caching
A developer wants an algorithm where tasks recursively fork and later combine results. Which method should be used?
Grand Central Dispatch
Fork-Join model
Pthreads mutex
Hybrid paging
To implement parallel loops in C using compiler directives, the developer should use:
GCD closures
OpenMP
Java Runnable
TBB only
When using OpenMP, adding #pragma omp parallel results in:
A. A single serial thread
B. Threads equal to number of CPU cores
C. One kernel thread per process
D. Threads only on Windows
A task queue where multiple items run concurrently in FIFO order is which GCD queue type?
Serial
Priority
Concurrent
Random
A developer uses the Java Executor Framework instead of manually creating threads. What is applied?
Implicit threading
Direct thread scheduling
Kernel thread binding
Memory swapping
To achieve parallel C++ loops using Intel TBB, which construct should be applied?
parallel_for
omp_task
dispatch_sync
exec_thread
To cancel a thread only at safe points, which cancellation type applies?
Forced cancellation
Asynchronous cancellation
Deferred cancellation
Timed cancellation
A Java developer checks Thread.currentThread().isInterrupted(). What is applied?
A UNIX program needs a user-defined function to process events like segmentation faults. Which mechanism applies?
Paging handler
Interrupt vector
Signal handler
Register swapping
To send all signals to one dedicated thread, which strategy applies?
Deliver to all threads
Deliver to random thread
Deliver to specific assigned thread
Ignore signals
Which mechanism maintains correct number of kernel threads in M:M threading?
Thread cloning
Scheduling activations
JNI callbacks
Deadlock detection
To bind a user thread to a kernel thread in M:M mapping, which model applies?
One-to-One
Two-Level model
Many-to-One
Hybrid paging model
To implement POSIX-compliant threads in Linux, which API is applied?
LWP API
Pthreads
GCD API
WinThread API
Using pthread_join() applies which concept?
Thread synchronization
Thread cancellation
Thread pooling
Interrupt dispatch
A Windows program using CreateThread() applies which model?
Many-to-one
Single-threaded
One-to-one
Signal-based threading
A system using clone() to create tasks that share address space refers to which OS?
Windows
macOS
Linux
BSD
In GCD, tasks are assigned to available threads from:
User thread pool
Kernel-controlled thread pool
Manual thread list
Local thread counter
Splitting data across cores for identical operations is:
Task pipelining
Data parallelism
Linked scheduling
Mutual exclusion
A queue removing tasks in FIFO concurrently represents:
Thread binding
Scheduler activation
GCD concurrent queue
Exec handler
The register set, stacks, and private storage of a thread are called:
Thread-local swap
Thread context
Page frame
Hardware interrupt
TLS is used when the programmer must prevent:
Stack overflow
Data overwrite among threads
Page faults
If fork() should not duplicate all threads, which semantic applies?
Full duplication
Single-threaded duplication
Random duplication
Deferred duplication
Branching and joining tasks is characteristic of:
OpenMP
Fork-join parallelism
Thread cancellation
Windows scheduler
dispatch_async() in Swift triggers:
Synchronous execution
Immediate blocking
Asynchronous task dispatch
Thread cancellation
Faster creation and switching of threads than processes is which benefit?
Scalability
Responsiveness
Economy
Resource duplication
Debugging multithreaded programs on multicore CPUs is difficult due to:
Reduced stack usage
Data dependencies
Smaller register files
Lower clock speed
A server creating a new thread for each request represents:
Single-thread loop
Multithreaded server architecture
Kernel swapping
Deferred cancellation
Multiple tasks running simultaneously on multicore hardware represent:
(a)
Which of the following is a method for avoiding deadlocks?
Preemption
Parallelism
Deadlock avoidance
Kernel thread reassignment
pthread_testcancel() introduces:
Immediate cancellation
A cancellation point
Thread ID reset
Kernel thread reassignment
To return a value in Java threading, the developer uses:
Runnable
RecursiveAction
Callable with Executor
ThreadLocal
In Windows, user-mode stack and TLS are stored in:
ETHREAD
KTHREAD
TEB
PCB
To create a thread and wait for it to finish in Windows:
CreateThread() → WaitForSingleObject()
clone() → exec()
pthread_create() → pthread_join()
dispatch_sync() → dispatch_wait()
To parallelize loops in C++ using templates, use:
Pthreads
TBB
GCD
OpenMP only
Thread pools support applications where tasks:
Require manual termination
Are created frequently
Must run serially
Must block main thread
Delivering a signal to all threads is useful when:
The signal applies globally
Only one thread needs it
Signals must be suppressed
OS prohibits per-thread signals
If cancellation is pending but disabled, it occurs when:
Thread exits abruptly
Thread enables cancellation later
Kernel forces termination
Scheduler swaps stacks
OS determining optimal kernel threads relates to:
1:1
M:1
M:M
No threading
A dedicated thread handling all cleanup = assigning:
Signal handler thread
Clone() child
Runnable wrapper
Memory dispatcher
A Linux thread created via clone() sharing address space is:
Independent process
User-level thread only
Kernel-level task
Forked VM copy
A software team wants to prevent UI freezing during long operations. Which concept helps?
Paging
Multithreading
CPU scheduling
Memory compaction
Splitting array subsets for identical operations shows:
Serial execution
Data parallelism
Interrupt-driven flow
When serial code limits speedup regardless of cores, which law applies?
Little’s Law
Amdahl’s Law
Murphy’s Law
Newton’s Law
A developer needs each user thread mapped to one kernel thread:
M:1
1:1
M:M
Two-level only
In M:1, if a thread blocks during I/O:
Other threads continue
All user threads block
Kernel creates new threads
Memory grows
To maximize concurrency but limit kernel threads:
M:1
1:1
M:M
Serial execution
Which system most commonly supports Pthreads?
Windows
UNIX-like systems
DOS
ChromeOS only
pthread_exit() is used to:
Destroy mutex
Swap context
Terminate a thread safely
Replace the process
WaitForSingleObject() is used to:
Java threads most commonly use:
Runnable
Comparator
Clonable
Iterator
A thread that returns a value in Java uses:
Runnable
Callable
ThreadGroup
Volatile
To avoid recreating threads repeatedly:
Serial queue
Thread pools
Direct signals
Manual scheduling
Which directive runs code in parallel in C/C++?
#pragma omp thread
#pragma omp start
#pragma omp parallel
#pragma omp swap
To parallelize loops using OpenMP:
#pragma omp for
#pragma omp gather
#pragma omp lock
#pragma omp exec
Tasks placed in a dispatch queue on macOS use:
TBB
Pthreads
Grand Central Dispatch
OpenCL
A serial queue executes:
Items in parallel
Items in FIFO one at a time
Based on priority only
Based on thread ID
A recursive computation divided into subtasks uses:
Memory swapping
Fork-join parallelism
Single-threaded loops
Paging algorithms
The C++ parallel_for construct comes from:
Linux kernel
Windows API
TBB library
Java threading
A cancellation that only occurs at defined points:
Hard cancellation
Deferred cancellation
Immediate cancellation
Random cancellation
Delivering signals to the appropriate thread relates to:
Deadlock prevention
Paging
Signal handling
Stack overflow
clone() creates threads in:
Windows
Linux
Solaris only
RTOS only
TLS stores:
Shared values
Per-thread values
Kernel-only values
Process-wide constants
pthread_testcancel() is an example of:
A. A locking primitive
B. A cancellation point
C. A clone operation
D. A memory handler
Scheduler activations deliver:
Signals from users to kernel
User notifications
Upcalls from kernel to thread library
Debug output
Java thread pools created via Executors are:
Explicit threading
Implicit threading
Hardware threads
Kernel threads
#pragma omp parallel instructs compiler to:
Force a single thread
Create threads equal to CPU cores
Disable threading
Bind threads to memory
In a multithreaded server, the first step is usually:
Thread termination
Client request arrival
Load balancing
Deadlock resolution
The combined register set and stacks of a thread represent:
Process descriptor
Thread context
Kernel buffer
Execution shadow
79. M:1 cannot use multicore because:
No registers exist
Only one kernel thread runs
Which benefit is most relevant for CPU-intensive workloads?
Economy
Scalability
Small memory footprint
Fewer interrupts
Concurrency without parallelism occurs when:
Multiple cores run code
A single core switches tasks
Many tasks are queued
No threads exist
Which threading model is least commonly used today?
M:M
M:1
1:1
Two-level
worker.join() in Java:
Starts thread
Waits for its completion
Cancels thread instantly
Returns thread priority
A GCD concurrent queue:
Runs one item at a time
Can run multiple items concurrently
Cancels tasks automatically
Creates new processes
Choosing which thread receives a signal relates to:
Scheduling
Signal semantics
Memory management
Paging
A normal exit, A type of mutex lock, A directory update
A. A normal exit
B. Forced termination before completion
C. A type of mutex lock
D. A directory update
Thread pools wait for:
Swaps
Kernel interrupts
Tasks
Paging signals
GCD assigns tasks to:
User-level threads only
Available kernel threads
Disk scheduler
Memory queue
Fork-join results combine during:
Fork phase
Memory allocation
Join phase
Blocking
RecursiveTask:
Returns no value
Returns a value
Must be serial
Cannot fork
OpenMP identifies parallel sections using:
parallel regions
exec sections
sync blocks
atomic blocks
Kernel-mode thread data is stored in:
PCB
ETHREAD
KTHREAD
TEB
TBB parallel_for is designed to:
Restart CPU core
Replace recursion
Parallelize loop iterations
Manage files
TLS persists across:
Process terminations
Function calls within a thread
OS restarts
Kernel rebuilds
M:M allows OS to:
Disable user threads
Choose number of kernel threads
Prevent concurrency
Duplicate processes
If all user threads block when one blocks, the system is:
1:1
M:M
Two-level
M:1
Linux thread behavior is set via:
CreateThread()
TaskPool()
clone() flags
Ring buffer
Debugging explicit threads becomes difficult due to:
Stable thread state
Reduced correctness from complexity
Static memory mapping
No concurrency
A thread pool improves performance when:
Threads rarely run
Threads must be recreated each time
Many small tasks must execute
