Lecture 10 Flashcards

1
Q

What is implicit threading?

A

To transfer the creation and management of threading from application developers to compilers and run-time libraries.

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

What is the advantage of implicit threading?

A

The advantage of this approach is that the developers only need to identify parallel tasks, and the libraries determine the specific details of thread creation and management.

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

What is a task in reference to implicit threading?

A

A task is usually written as a function, which the run-time library then maps to a separate thread, typically using the many-to-many model.

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

What are the issues related to implicit threading?

A

There are two issues regarding implicit threading:
1. The amount of work required in thread creation is a complete overhead given the fact that a thread is discarded after it has completed its work.
2. There is no bound on the number of threads concurrently active in the system and this can exhaust system resources such as CPU time or memory.

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

How can we place a bound on the number of threads created/ or on the number of threads concurrently active in the system?

A

The solution is to use thread pool.

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

What’s the general idea of a thread pool?

A
  1. Create a number of threads at start-up and place them into a pool where they sit and wait for work.
  2. When the system receives a request, it is submitted to the thread pool.
  3. If there is a thread available to process the request, it is awakened and the request is serviced immediately.
  4. Once a thread completes its service, it returns to the pool and awaits more work.
  5. If there is no thread available, the task is queued until a thread becomes free.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Thread pool work well in ________________ execution of tasks.

A

Asynchronous

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

What are the benefits of thread pools?

A
  1. Servicing a request with an existing thread is often faster than waiting to create a thread.
  2. A thread pool limits the number of threads that exist at any one point. This is particularly important in systems with limited resources.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is a synchronous version of thread or explicit thread creation?

A

Creation of thread using fork-join strategy.
1. The main parent thread creates(forks) one or more child threads.
2. Waits for the child to terminate.
3. Joins with it, at which point it can retrieve and join their results.

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

What is openMP?

A

OpenMP is an application programming interface that supports multi-platform shared-memory multiprocessing programming in C, C++, and Fortran, on many platforms, instruction-set architectures and operating systems, including Solaris, AIX, FreeBSD, HP-UX, Linux, macOS, and Windows.

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

How does openMP works?

A
  1. OpenMP identifies parallel regions as blocks of code that may run in parallel.
  2. It creates as many threads as there are processing cores in the system.
  3. All the threads then simultaneously execute the parallel region.
  4. As each thread exits the parallel region, it is terminated.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is GCD(Grand Central Dispatch)?

A
  1. Grand Central Dispatch (GCD) is a technology developed by Apple for its macOS and iOS operating systems.
  2. It is a combination of a run-time library, an API, and language extensions that allow developers to identify sections of code (tasks) to run in parallel.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How does GCD work?

A
  1. It schedules tasks for run-time execution by placing them on a dispatch queue.
  2. When it removes a task from the queue, it assigns the task to an available thread from a pool of threads that it manages.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What are private dispatch queues?

A

The additional serial queues created by developers that are local to a particular process.

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

What’s the difference between serial and concurrent queues?

A

Serial Queue:
1. A single task is removed from the queue.
2. Once a task has been removed from the queue, it must complete execution before another task is removed.

Concurrent Queue:
1. Several tasks may be removed at a time.
2. Multiple tasks can be executed in parallel.

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

Both sequential and concurrent queues remove tasks in _________ order.

A

FIFO

17
Q

What are the four classes in which the system-wide concurrent queues are divided?

A
  1. QOS CLASS USER INTERACTIVE
  2. QOS CLASS USER INITIATED
  3. QOS CLASS UTILITY
  4. QOS CLASS BACKGROUND
18
Q

What are two ways in which tasks submitted to dispatch queues are expressed?

A

Obj-C(uses block) or Swift(uses closure)

19
Q

GCD’s thread pool is composed of _______threads.

A

POSIX

20
Q

How does GCD manage the thread pool?

A

It actively manages the pool, allowing the number of threads to grow and shrink according to application demand and system capacity.

21
Q

If one thread in a program calls fork(), does the new process duplicate all threads, or is the new process single-threaded?

A

Some UNIX systems have chosen to have two versions of fork(), one that duplicates all threads and another that duplicates only the thread that invoked the fork() system call.

22
Q

What happens when a thread invokes exec() system call?

A

The program specified in the parameter to exec() will replace the entire process—including all threads.

23
Q

A ______ is used in UNIX systems to notify a process that a particular event has occurred.

A

signal

24
Q

Why a signal is created by a process?

A
  1. A signal is generated by the occurrence of a particular event such as illegal memory access and division by 0.
  2. The signal is delivered to a process.
  3. Once delivered, the signal must be handled.
25
Q

What are two signal handlers?

A
  1. A default signal handler( default handler run by the kernel)
  2. A user-defined signal handler
26
Q

What are the ways of delivering signals in a multi-threaded program?

A
  1. Deliver the signal to the thread to which the signal applies.
  2. Deliver the signal to every thread in the process.
  3. Deliver the signal to certain threads in the process.
  4. Assign a specific thread to receive all signals for the process
27
Q

What is thread cancellation?

A

Thread cancellation involves terminating a thread before it has been completed.

28
Q

What is a target thread?

A

A thread that is to be cancelled is often referred to as the target thread.

29
Q

What are the issues with thread cancellation?

A

The difficulty with cancellation occurs in situations where:
1. Resources have been allocated to a cancelled thread.
2. A thread is cancelled while in the midst of updating data it is sharing with other threads.

30
Q

Benefits of multi-threaded programming.

A

Threads belonging to a process share the data of the process

31
Q

What is thread-local storage?

A

A personal copy of certain data of a thread is called thread-local storage or TLS.

32
Q

TLS data may not be shared if ________

A

forked

33
Q

What is a lightweight process or LWP?

A

Many systems implementing either the many-to-many or the two-level model place an intermediate data structure between the user and kernel threads, this data structure is called LWP.