Multithreaded Programming Flashcards

(32 cards)

1
Q

What are the basic components of a thread?

A

Basic components include:
* Thread ID
* Program counter
* Register set
* Stack
* Thread-specific data

Threads are lightweight processes that share the same resources of the parent process.

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

What is the difference between threads and processes?

A

Threads share resources of the same process, while processes have separate memory spaces.

This makes thread creation lighter and faster compared to process creation.

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

What are the benefits of multithreaded applications?

A
  • Responsiveness
  • Resource Sharing
  • Economy
  • Scalability

Responsiveness is especially important for user interfaces, allowing continued execution even if part of the process is blocked.

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

What challenges do programmers face in multicore programming?

A
  • Dividing activities
  • Balance
  • Data splitting
  • Data dependency
  • Testing and debugging

These challenges arise due to the need for parallel execution across multiple cores.

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

Define concurrency.

A

Concurrency supports more than one task making progress simultaneously.

It can occur on a single-core system where the scheduler provides the illusion of parallelism.

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

What is parallelism?

A

Parallelism implies a system can perform more than one task simultaneously.

This typically occurs on multicore systems.

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

What is data parallelism?

A

Data parallelism distributes subsets of the same data across multiple cores, performing the same operation on each.

This is effective for operations that can be parallelized across large datasets.

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

What does Amdahl’s Law state?

A

Amdahl’s Law identifies performance gains from adding additional cores to an application that has both serial and parallel components.

It shows that the serial portion of an application has a disproportionate effect on performance.

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

What are user threads?

A

User threads are managed by user-level thread libraries.

Examples include POSIX Pthreads, Windows threads, and Java threads.

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

What are kernel threads?

A

Kernel threads are supported by the operating system kernel.

They are used in virtually all general-purpose operating systems like Windows and Linux.

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

What is the many-to-one threading model?

A

In the many-to-one model, many user-level threads are mapped to a single kernel thread.

A blocking user thread causes all threads to block, limiting parallel execution.

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

What is the one-to-one threading model?

A

In the one-to-one model, each user-level thread maps to a kernel thread.

This model allows more concurrency than many-to-one but may restrict the number of threads per process.

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

What characterizes the many-to-many threading model?

A

The many-to-many model allows many user-level threads to be mapped to many kernel threads.

This provides flexibility and is used in some operating systems, such as Windows with the ThreadFiber package.

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

What is a thread library?

A

A thread library provides an API for creating and managing threads.

It can be implemented in user space or as a kernel-level library.

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

What are the semantics of the fork() system call in threading?

A

The behavior of fork() varies; it may duplicate only the calling thread or all threads in some UNIX systems.

The exec() call generally replaces the running process, including all threads.

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

What is signal handling in multithreaded applications?

A

Signal handling can be synchronous or asynchronous, with threads specifying which signals to accept or block.

UNIX allows a thread to define its signal handlers, while Windows uses asynchronous procedure calls (APCs).

17
Q

Fill in the blank: A thread pool is a _______ for managing multiple threads efficiently.

A

collection of pre-initialized threads.

18
Q

True or False: In the one-to-one threading model, creating a user-level thread creates a kernel thread.

19
Q

What is thread-local storage?

A

Thread-local storage allows threads to maintain their own data without conflicts.

This is crucial for data that must not be shared between threads.

20
Q

What is the role of scheduler activations in threading?

A

Scheduler activations provide a mechanism to efficiently manage kernel threads and user threads.

They help in balancing the load between user-level threads and kernel scheduling.

21
Q

Where should a signal be delivered for multi-threaded processes?

A

Deliver the signal to the thread to which the signal applies

Other options include delivering to every thread, certain threads, or assigning a specific thread to receive all signals.

22
Q

What is thread cancellation?

A

Terminating a thread before it has finished

The thread to be canceled is the target thread.

23
Q

What are the two general approaches for thread cancellation?

A
  • Asynchronous cancellation terminates the target thread immediately
  • Deferred cancellation allows the target thread to periodically check if it should be cancelled
24
Q

What happens when a thread cancellation request is invoked?

A

Cancellation depends on thread state

If cancellation is disabled, it remains pending until enabled.

25
What is the default type of thread cancellation?
Deferred ## Footnote Cancellation occurs when the thread reaches a cancellation point, such as pthread_testcancel().
26
How is thread cancellation handled on Linux systems?
Through signals ## Footnote This mechanism allows for cancellation requests to be processed.
27
What is thread-local storage (TLS)?
Allows each thread to have its own copy of data ## Footnote Useful when you do not control the thread creation process, such as when using a thread pool.
28
How does TLS differ from local variables?
TLS is visible across function invocations while local variables are visible only during single function invocation.
29
What are scheduler activations?
A communication mechanism to maintain the appropriate number of kernel threads allocated to the application ## Footnote Typically involves an intermediate data structure called lightweight process (LWP).
30
What function do lightweight processes (LWP) serve?
Appear to be a virtual processor on which a process can schedule user threads to run.
31
What do scheduler activations provide?
Upcalls ## Footnote Upcalls are a communication mechanism from the kernel to the upcall handler in the thread library.
32
What is the purpose of the communication provided by scheduler activations?
Allows an application to maintain the correct number of kernel threads.