0% found this document useful (0 votes)
2 views

Os4 p2c4 Threads

The document discusses the concept of threads in computing, highlighting the benefits of multithreading such as responsiveness, resource sharing, economy, and scalability. It also outlines programming challenges associated with multithreading, including task identification, workload balance, data splitting, and debugging. Additionally, it covers different multithreading models, including user vs. kernel threads and their various mapping strategies.

Uploaded by

Thiện Nhân
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Os4 p2c4 Threads

The document discusses the concept of threads in computing, highlighting the benefits of multithreading such as responsiveness, resource sharing, economy, and scalability. It also outlines programming challenges associated with multithreading, including task identification, workload balance, data splitting, and debugging. Additionally, it covers different multithreading models, including user vs. kernel threads and their various mapping strategies.

Uploaded by

Thiện Nhân
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

Threads

Tran, Van Hoai

Faculty of Computer Science & Engineering


HCMC University of Technology

E-mail: [email protected]
(partly based on slides of Le Thanh Van)

1 / 20
Outline

1 Thread and its benefits

2 Multithreading models

2 / 20
Outline

1 Thread and its benefits

2 Multithreading models

3 / 20
Motivation

An application normally has several controls


A word-processor has a control on mouse input, a control for keyboard, a control for function completion,

...

The model “an application = a process” does not catch


up with multiprocessor environment
A modern processor has multiple cores

4 / 20
Single vs. Multithreaded processes

5 / 20
Single vs. Multithreaded processes

With the above model, one server (by one process) can service
several concurrent requests.

6 / 20
Benefits of multithreading model

Responsiveness: a program (process) continues running


even if a part of it is blocked or is performing a lengthy
operation.
Resource sharing: By defaults, threads share memory
and resources of its process ⇒ same address-space.
Economy: Resource allocation, context-switching are
time-consuming. Threads do it more economically.
Scalability: threads may be running in parallel on
different processing cores.

7 / 20
Benefits of multithreading model

Responsiveness: a program (process) continues running


even if a part of it is blocked or is performing a lengthy
operation.
Resource sharing: By defaults, threads share memory
and resources of its process ⇒ same address-space.
Economy: Resource allocation, context-switching are
time-consuming. Threads do it more economically.
Scalability: threads may be running in parallel on
different processing cores.

concurrency vs. parallelism


Concurrency = many tasks are allowed to make progress
Parallelism = many tasks can be performed simultaneously

8 / 20
Programming challenges

Identifying tasks: how to divide an application into


tasks ?
Balance: how tasks do the same amount of workload ?
Data splitting: how data of tasks to be splitted ?
Data dependency: data surely does not live alone, how
they are synchronized ?
Testing and debugging: how to follow many different
execution paths ?

9 / 20
Programming challenges

Identifying tasks: how to divide an application into


tasks ?
Balance: how tasks do the same amount of workload ?
Data splitting: how data of tasks to be splitted ?
Data dependency: data surely does not live alone, how
they are synchronized ?
Testing and debugging: how to follow many different
execution paths ?

Textbook
“Many computer science educators believe that software
development must be taught with increased emphasis on
parallel programming.”

10 / 20
Do not expect much on multiple threading

Amdahl’s Law
1
speedup ≤
S + 1−S
N

in which, S: serial portion; N: number of cores (threads).


11 / 20
Outline

1 Thread and its benefits

2 Multithreading models

12 / 20
User vs. Kernel threads

User threads
Thread management done by user-level thread library
Examples: POSIX Pthreads, Mach C-threads, Solaris
threads

Kernel threads
Thread management done at kernel-level by OS
Examples: Windows, Linux, Max OS X, Solaris

13 / 20
User vs. Kernel threads

User threads
Thread management done by user-level thread library
Examples: POSIX Pthreads, Mach C-threads, Solaris
threads

Kernel threads
Thread management done at kernel-level by OS
Examples: Windows, Linux, Max OS X, Solaris

A relationship must exist between user threads and kernel


threads

14 / 20
Many-to-one

Mapping many user-level threads to


one kernel thread
Issues:

15 / 20
Many-to-one

Mapping many user-level threads to


one kernel thread
Issues:
if a thread is blocked, the entire process is
blocked too.
Unable to run in parallel on multicore systems

16 / 20
One-to-one

Mapping each user thread to a kernel thread


Issues:

17 / 20
One-to-one

Mapping each user thread to a kernel thread


Issues:
Creating a user thread means creating a kernel thread ⇒ overhead.
Number of threads is restricted
Linux, Windows

18 / 20
Many-to-many

Multiplexing many user-level threads


to a smaller or equal number of kernel
threads
Issues:

19 / 20
Many-to-many

Multiplexing many user-level threads


to a smaller or equal number of kernel
threads
Issues:
Not so many OS implementations apply this
model, (Solaris supports)

20 / 20

You might also like