Threads

16 important questions on Threads

What is a thread?

A thread is a basic unit of CPU utilisation
-> it comprises a thread ID, a program counter, a register set and a stack

It shares its code section, data section, and other OS resources, such as open files, with other threads belonging to the same process

Why use a thread over a process?

- Process creation is heavy-weight while thread creation is light-weight
- Threads can simplify code, increase efficiency

What are 4 benefits of threads?

  1. Responsiveness - may allow continued execution if part of process is blocked, especially important for user interfaces
  2. Resource sharing - threads share resources of process, easier than shared memory or message passing
  3. Economy - cheaper than process creation, thread switching lower overhead than context switching
  4. Scalability - process can take advantage of multiprocessor architectures
  • Higher grades + faster learning
  • Never study anything twice
  • 100% sure, 100% understanding
Discover Study Smart

What is multicore programming (or multiprocessing)?

An integrated circuit to which two of more processors have been attached for enhanced performance, reduced power processing, and more efficient simultaneous processing of multiple tasks

What are 2 types of parallelism?

1. Data parallelism -> distributes subsets of the same data across multiple cores, same operation in each
2. Thread parallelism ->  distributing threads across cores, each thread performing unique operation

What is the many-to-one model?

Many user-level threads mapped to a single kernel thread

- one thread blocking causes all the threads to block
- multiple threads may not run in parallel on multicore system because only one may be in kernel at a time

(few systems use this model)

What is the one-to-one model?

- each user-level thread maps to a kernel thread
- creating a user-level thread creates a kernel thread

- more concurrency than many-to-one  

- Number of threads per process sometimes restricted due to overhead

What is a thread library?

A thread library provides the programmer with API for creating and managing threads

Two ways of implementing:
  • library entirely in user space
  • Kernel-level library supported by OS  

What are the 3 main thread libraries in use today?

  1. POSIX Pthreads (The Portable Operating System Interface)
  2. Windows threads
  3. Java threads

What is the Pthread library?

- may be provided either as user-level or kernel-level
- common in UNIX operating systems
- API specifies behaviour of the thread library, implementation is up to the development of the library

What are Java threads?

- Java threads are managed by the JVM
- typically implemented using the threads model provided by underlying OS
- Java threads may be created by extending thread classes or implementing the Runnable interface 

What is implicit threading?

Creation and management of threads done by compilers and run-time libraries rather than programmers
--> implicit threading is growing in popularity as numbers of threads increase, program correctness is more difficult with explicit threads

What are 3 implicit threading methods?

  1. Thread pools
  2. Open MP
  3. Grand Central Dispatch

What is the thread pools method and what are its advantages?

Create a number of thread in a pool where they await work

Advantages:
  • Usually slightly faster to service a request with an existing thread than create a new thread  
  • Allows the number of threads in the application(s) to be bound to the size of the pool
  • Separating task to be performed from mechanics of creating task allows different strategies for running task (i.e. tasks could be scheduled to run periodically)

What is openMP method?

Set of compiler directives and an API for C, C++, FORTRAN

Provides support for parallel programming in shared-memory environments 

Identifies parallel regions (blocks of code that can run in parallel)

What is the grand central dispatch method?

- apple technology for Mac OS X and iOS operating systems
- allows identification of parallel sections
- manages most of the details of threading 
- blocks placed in dispatch queue --> assigned to available thread in thread pool when removed from queue

The question on the page originate from the summary of the following study material:

  • A unique study and practice tool
  • Never study anything twice again
  • Get the grades you hope for
  • 100% sure, 100% understanding
Remember faster, study better. Scientifically proven.
Trustpilot Logo