Chapter 4 Flashcards

(32 cards)

1
Q

What is a thread?

A

A lightweight process that represents the smallest unit of CPU execution with its own program counter, registers, and stack, but shares code and data with other threads in the same process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the main difference between a process and a thread?

A

A process has its own memory space; threads within a process share the same memory space.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What do threads share in a multithreaded process?

A

Code section, data section, and open files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What resources are unique to each thread?

A

Program counter, registers, and stack.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Why do modern applications use threads?

A

To increase responsiveness and efficiency by performing multiple tasks concurrently within a single process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does responsiveness mean in multithreading?

A

One thread can continue executing even if another is blocked (e.g., waiting for I/O).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How does multithreading support resource sharing?

A

All threads share process resources so they can communicate easily without inter-process communication overhead.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Why is thread creation more economical than process creation?

A

Threads share the same address space, so creating them requires less memory and CPU overhead than a new process.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does scalability mean in multithreading?

A

Threads can run on multiple processors simultaneously to improve performance.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Give an example of a multithreaded application.

A

A web server handling multiple client requests at once.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are user threads?

A

Threads managed in user space by a thread library without kernel awareness.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are kernel threads?

A

Threads supported and managed directly by the operating system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are the three main multithreading models?

A

Many-to-One, One-to-One, and Many-to-Many.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Describe the Many-to-One model.

A

Many user threads mapped to a single kernel thread; entire process blocks if one thread blocks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Describe the One-to-One model.

A

Each user thread maps to a kernel thread; allows true parallelism on multiprocessors but is costly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Describe the Many-to-Many model.

A

Multiple user threads mapped to a pool of kernel threads for flexibility and non-blocking calls.

17
Q

What is the Two-Level model?

A

A variation of Many-to-Many that can behave as either Many-to-Many or One-to-One.

18
Q

In which model does a blocking system call block the entire process?

19
Q

In which models can multiple threads run concurrently on a multiprocessor system?

A

One-to-One and Many-to-Many.

20
Q

What is a thread library?

A

An API that provides functions for creating and managing threads.

21
Q

Name three common thread libraries.

A

Pthreads (POSIX), Win32 threads, and Java threads.

22
Q

What does pthread_create() do?

A

Creates a new thread and assigns it a function to execute.

23
Q

What does pthread_join() do?

A

Makes the calling thread wait for another thread to finish execution.

24
Q

What is the purpose of pthread_exit()?

A

Terminates the calling thread without ending the entire process.

25
What does the ‘-pthread’ flag do in compilation?
Links the program with the Pthreads library and enables thread-safe compilation.
26
What is the difference between pthread_create() and pthread_exit()?
pthread_create starts a new thread; pthread_exit ends a thread safely without terminating others.
27
Why should main() call pthread_exit(NULL)?
To prevent main from terminating before other threads complete.
28
What happens if the main thread ends before child threads complete?
The entire process terminates, and unfinished threads are killed.
29
What is a race condition in threads?
When two threads access shared data simultaneously and the result depends on timing.
30
What tool prevents race conditions in multithreading?
A mutex lock or other synchronization primitive.
31
What is the difference between joining and detaching a thread?
Joined threads block the caller until they finish; detached threads run independently without join.
32
Why are kernels often multithreaded?
To handle multiple tasks (e.g., I/O requests, interrupts) concurrently for better efficiency.