Threads - Chapter 4

Thread - light weight process created by a process

Each thread has its own:

They share:

Advantages

Responsiveness - applications appear to be running at the same time

Resource sharing - threads can be working on the same data

Economy - easier to make a thread than a process

Scalable - threads can run on multi-cores

Concurrent vs Parallelism

Concurrent - multiple threads/processes are running multi tasking (can be one or multiple cores)

Parallel - multiple threads/processes can be running at the same time (must be multiple cores)

Challenges associated with programming threads

Knowing what should be parallel

Threads should have an equal work load

Data must be split to run on separate cores

Data access must be synchronised

Hard to debug, and test

Types of parallelism

Data parallelism - data is divided into chunks that can be processes by separate cores performing the same task

Task parallelism - each core is performing a separate operation

User-threads and Kernel-threads

User-thread:

Kernel-thread:

Threading models

Since each user thread needs to be assigned to a kernel thread, there are different ways of going about it

Many-to-one

One-to-one

Many-to-many