Threads and Concurrency

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/27

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

28 Terms

1
New cards

What is concurrency?

The ability for a system to run multiple independent but related tasks simultaneously or interleaved, improving efficiency on multi-processor systems.

2
New cards

Why is concurrency needed?

A sequential program uses only one processor. Concurrency allows multiple processors to execute separate or related tasks for better utilization.

3
New cards

What's the most efficient IPC mechanism for concurrency?

Shared memory — no copying between buffers and minimal system call overhead after setup.

4
New cards

What are the downsides of using processes for concurrency?

High cost of creating/destroying processes and expensive context switching.

5
New cards

What is a thread?

A lightweight execution unit within a process that shares the same address space and resources with other threads.

6
New cards

Why use threads instead of processes?

Threads allow concurrency with lower overhead and faster context switching since they share memory.

7
New cards

What is a Thread Control Block (TCB)?

A data structure maintained by the kernel that stores thread-specific info (analogous to the PCB for processes).

8
New cards

What are User-Level Threads (ULT)?

Threads managed entirely in user space without kernel involvement.

9
New cards

Advantages of ULT?

Low overhead, customizable scheduling, no mode switch needed.

10
New cards

Disadvantages of ULT?

No true parallelism — one thread blocks the entire process.

11
New cards

What are Kernel-Level Threads (KLT)?

Threads managed directly by the OS kernel, allowing true parallelism.

12
New cards

Advantages of KLT?

Independent progress and optimal CPU utilization.

13
New cards

Disadvantages of KLT?

High overhead — creating/destroying threads requires kernel calls and mode switches.

14
New cards

What is Many-to-One threading?

Multiple user threads mapped to one kernel thread.

15
New cards

What is One-to-One threading?

Each user thread corresponds to one kernel thread (e.g., Windows, Linux).

16
New cards

What is Many-to-Many threading?

Multiple user threads mapped to multiple kernel threads (hybrid model).

17
New cards

What is Scheduler Activation?

A user-space scheduling mechanism once used for hybrid threading (now mostly abandoned).

18
New cards

What's the issue with fork and exec in multithreaded programs?

Whether the new process should copy all threads or just the calling one — copying all is inefficient.

19
New cards

What's a common solution?

The process invokes fork, and the child immediately calls exec to start fresh.

20
New cards

What are the main signal-handling options in multithreaded systems?

Send signal to: all threads, specific threads, designated thread, or the one the signal applies to.

21
New cards

What are the two main types of thread cancellation?

Asynchronous (immediate kill) and Deferred (thread periodically checks a cancel flag).

22
New cards

Why is deferred cancellation preferred?

Prevents data corruption if the thread is modifying shared data.

23
New cards

What is Thread-Local Storage?

A mechanism giving each thread its own copy of certain variables.

24
New cards

Why use TLS?

Prevents data races and allows compiler optimizations.

25
New cards

Where is TLS data stored?

As static data, persisting even after thread termination.

26
New cards

What is a Thread Pool?

A group of pre-created worker threads used to handle tasks dynamically.

27
New cards

Why use a Thread Pool?

Reduces overhead of creating/destroying threads and improves runtime efficiency.

28
New cards

What is Grand Central Dispatch (GCD)?

Apple's efficient implementation of thread pools for managing concurrent operations.