Lecture 10 Flashcards
What is implicit threading?
To transfer the creation and management of threading from application developers to compilers and run-time libraries.
What is the advantage of implicit threading?
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.
What is a task in reference to implicit threading?
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.
What are the issues related to implicit threading?
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 can we place a bound on the number of threads created/ or on the number of threads concurrently active in the system?
The solution is to use thread pool.
What’s the general idea of a thread pool?
- Create a number of threads at start-up and place them into a pool where they sit and wait for work.
- When the system receives a request, it is submitted to the thread pool.
- If there is a thread available to process the request, it is awakened and the request is serviced immediately.
- Once a thread completes its service, it returns to the pool and awaits more work.
- If there is no thread available, the task is queued until a thread becomes free.
Thread pool work well in ________________ execution of tasks.
Asynchronous
What are the benefits of thread pools?
- Servicing a request with an existing thread is often faster than waiting to create a thread.
- A thread pool limits the number of threads that exist at any one point. This is particularly important in systems with limited resources.
What is a synchronous version of thread or explicit thread creation?
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.
What is openMP?
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 does openMP works?
- OpenMP identifies parallel regions as blocks of code that may run in parallel.
- It creates as many threads as there are processing cores in the system.
- All the threads then simultaneously execute the parallel region.
- As each thread exits the parallel region, it is terminated.
What is GCD(Grand Central Dispatch)?
- Grand Central Dispatch (GCD) is a technology developed by Apple for its macOS and iOS operating systems.
- 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 does GCD work?
- It schedules tasks for run-time execution by placing them on a dispatch queue.
- When it removes a task from the queue, it assigns the task to an available thread from a pool of threads that it manages.
What are private dispatch queues?
The additional serial queues created by developers that are local to a particular process.
What’s the difference between serial and concurrent queues?
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.
Both sequential and concurrent queues remove tasks in _________ order.
FIFO
What are the four classes in which the system-wide concurrent queues are divided?
- QOS CLASS USER INTERACTIVE
- QOS CLASS USER INITIATED
- QOS CLASS UTILITY
- QOS CLASS BACKGROUND
What are two ways in which tasks submitted to dispatch queues are expressed?
Obj-C(uses block) or Swift(uses closure)
GCD’s thread pool is composed of _______threads.
POSIX
How does GCD manage the thread pool?
It actively manages the pool, allowing the number of threads to grow and shrink according to application demand and system capacity.
If one thread in a program calls fork(), does the new process duplicate all threads, or is the new process single-threaded?
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.
What happens when a thread invokes exec() system call?
The program specified in the parameter to exec() will replace the entire process—including all threads.
A ______ is used in UNIX systems to notify a process that a particular event has occurred.
signal
Why a signal is created by a process?
- A signal is generated by the occurrence of a particular event such as illegal memory access and division by 0.
- The signal is delivered to a process.
- Once delivered, the signal must be handled.