Threads Lecture Overview
- 29Unfamiliar
- 0Learning
- 0Familiar
- 0Mastered
What is the primary reason for using threads in a process?
What is the primary reason for using threads in a process?
29 questions
- 1
What is the primary reason for using threads in a process?
- A
To perform multiple tasks concurrently within a single process
- B
To reduce the need for hardware upgrades
- C
To simplify programming by eliminating system calls
- D
To increase the number of processes running simultaneously
Correct answer
ATo perform multiple tasks concurrently within a single process
Explanation
Threads allow a process to perform multiple tasks at the same time, such as handling user input and updating the display simultaneously.
- A
- 2
Which of the following is an example of using threads in a game?
- A
Running the game as a background process
- B
Disabling sound to improve performance
- C
Having separate threads for keyboard input and screen updates
- D
Using a single thread to load the entire game
Correct answer
CHaving separate threads for keyboard input and screen updates
Explanation
In a game, threads can handle keyboard input and screen updates concurrently, avoiding the need to alternate between tasks.
- A
- 3
Threads can be used to run the same algorithm on different data sets in parallel. This is commonly done for which task?
- A
Rendering a video
- B
Updating a network connection
- C
Managing file I/O
- D
Spell checking a document
Correct answer
ARendering a video
Explanation
For rendering a video, the same algorithm can be applied to different parts of the data in parallel using multiple threads.
- A
- 4
Which of the following applications would benefit from multithreading?
- A
A word processor with real-time spell checking
- B
A simple calculator that performs one operation at a time
- C
A command-line tool that reads a file and exits
- D
A static web page displaying text
Correct answer
AA word processor with real-time spell checking
Explanation
Real-time spell checking benefits from a background thread that continuously checks grammar while the user types.
- A
- 5
What must the operating system provide for threads to be used by applications?
- A
A new file system
- B
A dedicated processor for each thread
- C
Services and an API for creating and managing threads
- D
Automatic thread creation for every program
Correct answer
CServices and an API for creating and managing threads
Explanation
The OS must offer thread services via an API, which applications can call to create and manage threads.
- A
- 6
Why are most modern operating systems multithreaded?
- A
Because threads are easier to program than processes
- B
Because threads consume more memory than processes
- C
Because they are designed to run on single-core processors
- D
Because modern hardware often has multiple cores or processors
Correct answer
DBecause modern hardware often has multiple cores or processors
Explanation
Modern hardware with multiple cores or processors allows multithreaded processes to run in parallel, improving performance.
- A
- 7
How does the operating system adapt to new hardware such as a wireless trackball?
- A
By adding a device driver to support the new hardware
- B
By replacing the entire kernel
- C
By rewriting all system calls
- D
By disabling existing hardware support
Correct answer
ABy adding a device driver to support the new hardware
Explanation
The OS evolves by adding drivers to support new hardware, such as Bluetooth and additional features like scroll wheels.
- A
- 8
What is a key advantage of using threads over processes for concurrent tasks?
- A
Threads cannot share memory, making them more secure
- B
Threads require separate memory spaces for each task
- C
Threads are easier to debug than processes
- D
Threads are less resource-heavy because they share the code, data, and files of the parent process
Correct answer
DThreads are less resource-heavy because they share the code, data, and files of the parent process
Explanation
Threads share the same resources (code, data, files) as the parent process, making them lighter than creating separate processes.
- A
- 9
In the client-server approach to threads, who creates the new thread?
- A
The kernel
- B
The user
- C
The hardware
- D
The client process
Correct answer
AThe kernel
Explanation
The kernel creates new threads in response to client requests, acting as the server.
- A
- 10
How does multithreading help maintain responsiveness in a word processor?
- A
By running all tasks in a single thread
- B
By blocking user input until calculations are complete
- C
By allowing a background thread to continue spell checking while the UI remains responsive
- D
By using multiple processes for each task
Correct answer
CBy allowing a background thread to continue spell checking while the UI remains responsive
Explanation
The spell check thread runs in the background, so the UI thread remains responsive to user input.
- A
- 11
Why is inter-thread communication cheaper than inter-process communication?
- A
Threads require encryption for all communication
- B
Threads use separate network connections
- C
Threads share the same memory space, so they can access shared data directly
- D
Threads rely on message passing, which is efficient
Correct answer
CThreads share the same memory space, so they can access shared data directly
Explanation
Since threads share memory, they can directly access shared data without the overhead of message passing.
- A
- 12
What is a challenge when programming with threads?
- A
Threads eliminate the need for error handling
- B
Threads automatically synchronize access to shared data
- C
Managing shared data and avoiding race conditions is difficult
- D
Threads cannot be created dynamically
Correct answer
CManaging shared data and avoiding race conditions is difficult
Explanation
One of the main challenges is synchronizing access to shared data to prevent race conditions.
- A
- 13
What is the difference between parallelism and concurrency?
- A
Concurrency is the same as parallelism
- B
Parallelism means multiple tasks make progress but only one at a time; concurrency means tasks run simultaneously
- C
Parallelism means tasks run simultaneously; concurrency means multiple tasks make progress but are interleaved
- D
Parallelism is only possible on single-core systems
Correct answer
CParallelism means tasks run simultaneously; concurrency means multiple tasks make progress but are interleaved
Explanation
Parallelism requires multiple cores and runs tasks at the same time; concurrency allows multiple tasks to make progress by interleaving execution.
- A
- 14
What is data parallelism?
- A
Executing the same task on multiple datasets sequentially
- B
Running different tasks on the same data
- C
Splitting data into chunks and processing each chunk on a different core
- D
Using a single thread to process all data sequentially
Correct answer
CSplitting data into chunks and processing each chunk on a different core
Explanation
Data parallelism divides data into chunks and processes each chunk in parallel, often using the same algorithm.
- A
- 15
What is task parallelism?
- A
Running different tasks (e.g., editing and spell checking) simultaneously
- B
Splitting data and processing it in parallel
- C
Executing tasks one after another on different cores
- D
Running the same task on different data sets
Correct answer
ARunning different tasks (e.g., editing and spell checking) simultaneously
Explanation
Task parallelism involves executing different tasks concurrently, such as editing, spell checking, and displaying.
- A
- 16
What hardware support is needed for threads to run in parallel?
- A
A single fast processor
- B
Very large hard drives
- C
A high-speed network interface
- D
Multiple sets of registers and stacks
Correct answer
DMultiple sets of registers and stacks
Explanation
For threads to run in parallel, the hardware must provide multiple registers and stacks to keep each thread's context.
- A
- 17
What does 'thread context' refer to?
- A
The thread's name and identifier
- B
The state of the thread, including registers and stack
- C
The thread's priority level
- D
The thread's associated file descriptors
Correct answer
BThe state of the thread, including registers and stack
Explanation
Thread context includes the registers, stack, and other execution state needed to resume the thread.
- A
- 18
According to Amdahl's Law, what limits the speedup from adding more cores?
- A
The amount of memory available
- B
The serial portion of the application
- C
The clock speed of the processor
- D
The number of threads in a process
Correct answer
BThe serial portion of the application
Explanation
Amdahl's Law states that speedup is limited by the fraction of the application that must be executed sequentially.
- A
- 19
If an application is 75% parallelizable and 25% serial, doubling the number of cores from 1 to 2 gives approximately what speedup?
- A
1.25 times
- B
2.0 times
- C
1.6 times
- D
1.33 times
Correct answer
C1.6 times
Explanation
Using Amdahl's Law: speedup =1/(0.25+0.75/2)=1/(0.25+0.375)=1/0.625=1.6.
- A
- 20
What is the main drawback of the many-to-one thread model?
- A
If one user thread blocks, all user threads in the process block
- B
It is only available in Linux
- C
It requires many kernel threads
- D
It provides true parallelism
Correct answer
AIf one user thread blocks, all user threads in the process block
Explanation
In the many-to-one model, all user threads are mapped to a single kernel thread, so if one blocks, the entire process blocks.
- A
- 21
Which thread model maps each user thread to a separate kernel thread?
- A
One-to-one
- B
Many-to-many
- C
Two-level
- D
Many-to-one
Correct answer
AOne-to-one
Explanation
The one-to-one model creates one kernel thread for each user thread, allowing true parallelism.
- A
- 22
Which operating systems use the one-to-one thread model?
- A
Unix and BSD
- B
RTOS and Embedded systems
- C
macOS and Android
- D
Windows and Linux
Correct answer
DWindows and Linux
Explanation
Windows and Linux both implement the one-to-one model.
- A
- 23
What is a characteristic of the many-to-many thread model?
- A
It does not allow user-level threads to be created
- B
It binds each user thread to a specific kernel thread
- C
The number of kernel threads can be less than, equal to, or greater than the number of user threads
- D
It requires all threads to run on a single core
Correct answer
CThe number of kernel threads can be less than, equal to, or greater than the number of user threads
Explanation
In the many-to-many model, the OS manages user threads and kernel threads, allowing flexible mapping.
- A
- 24
How does the two-level thread model extend the many-to-many model?
- A
It eliminates user-level threads entirely
- B
It permits some user threads to be bound to specific kernel threads (one-to-one), while others are handled many-to-many
- C
It allows only one kernel thread per process
- D
It requires all threads to be in kernel space
Correct answer
BIt permits some user threads to be bound to specific kernel threads (one-to-one), while others are handled many-to-many
Explanation
The two-level model combines many-to-many with the ability to bind critical threads to dedicated kernel threads.
- A
- 25
Which of the following is a standard thread library for Unix-based systems?
- A
MFC Threads
- B
Windows Threads
- C
Java Threads
- D
Pthreads (POSIX threads)
Correct answer
DPthreads (POSIX threads)
Explanation
Pthreads (POSIX threads) is the standard on Unix/Linux systems.
- A
- 26
In Windows, what structure stores the thread's context (registers and stack)?
- A
Thread Context Block
- B
Kernel Thread
- C
Process Control Block
- D
Executive Thread
Correct answer
BKernel Thread
Explanation
The kernel thread structure holds the scheduling information, synchronization data, and the thread's stack (context).
- A
- 27
In Linux, how are threads created and how do they share resources?
- A
Using the pthread_create() call, which does not share any resources
- B
Using the exec() call, which replaces the current process
- C
Using the clone() call, which allows sharing of code, data, and files while creating a new stack
- D
Using the fork() call, which duplicates the entire process
Correct answer
CUsing the clone() call, which allows sharing of code, data, and files while creating a new stack
Explanation
Linux uses the clone() system call, which gives control over which resources to share (code, data, files) and creates a new stack.
- A
- 28
What does the clone() system call allow Linux threads to optionally share?
- A
Memory space, file system information, and signal handlers
- B
Only the program counter
- C
Only file descriptors
- D
Nothing; each thread has its own separate resources
Correct answer
AMemory space, file system information, and signal handlers
Explanation
The clone() call allows threads to share the file system, memory space, and signal handlers.
- A
- 29
Which thread library is used for Java applications?
- A
Pthreads
- B
Java threads (part of the Java language)
- C
Windows threads
- D
Linux threads
Correct answer
BJava threads (part of the Java language)
Explanation
Java has its own thread library built into the language.
- A

Ask anything
We've read this whole study set, so questions about it get the best answers.