Threads
Threads
Threads
OPERATING SYSTEMS
2
THREAD
• A thread,
• Thread ID
• Program counter,
• A group of register and
• Includes a stack structure.
• Threads commonly use the program code, data part,
operating system resources such as files.
• Classic processes have a single thread.
• If a process has more than one thread, it can
simultaneously do more than one task.
• Most of the software applications that work on modern
computers are working multithread on today.
3
THREAD (CONTINUES…)
thread thread
8
MULTI-CORE PROGRAMMING
9
MULTI-CORE PROGRAMMING
(CONTINUES…)
single core T1 T2 T3 T4 T1 T2 T3 T4 T1 …
time
core 1 T1 T3 T1 T3 T1 …
core 2 T2 T4 T2 T4 T2 …
time
10
MULTI-CORE PROGRAMMING
(CONTINUES…)
• CPU schedulers
• Ensure progress (continuity) by constantly switching
between processes and
• give the impression of parallelism.
• In fact, these processes
• They work concurrently.
• They do not work in parallel.
11
AMDAHL LAW
• Amdahl rule: The performance increase in a system according
to the number of cores is expressed as follows:
• S: refers to the ratio of the part that must be serially operated in
the application (non-parallel), and N: refers to the number of cores.
12
TYPES OF PARALLEL
WORKING
• Basically there are two different types of parallel
operation.
• Data parallelism
• Task parallelism
13
TYPES OF PARALLEL
WORKING ( C O N T I N U E S … )
2. Task Parallelism: It focuses on distributing tasks
(threads) to cores.
• Each thread performs a separate operation. Different
threads can work on the same data or different data.
• For example: Threads that perform different statistical
calculations on the same array elements using the same data
but running on different cores.
• Generally, the most applications use hybrid types of
both data and task parallel operation.
14
THREAD LIBRARIES
15
THREAD LIBRARIES ( C O N T I N U E S … )
16
PTHREADS
17
PTHREADS EXAMPLE 1
18
PTHREADS EXAMPLE 1
(CONTINUES…)
19
PTHREADS EXAMPLE 1 DETAILED
DESCRIPTION
PTHREADS EXAMPLE 2
21
.NET THREADS EXAMPLE 1
22
.NET THREADS EXAMPLE 1
23
PTHREADS EXAMPLE 1
(CONTINUES…)
• compile
o gcc -pthread -o SumThread SumThread.c
• execute
o ./SumThread 1000
24
PTHREADS EXAMPLE 1
(CONTINUES…)
26
PTHREADS EXAMPLE 1
(CONTINUES…)
28
PTHREADS EXAMPLE 2
(CONTINUES…)
29
PTHREADS EXAMPLE 2
(CONTINUES…)
• Change
31
RESOURCES
• Textbook:
• Operating System Concepts, Ninth Edition, Abraham
Silberschatz, Peter Bear Galvin, Greg Gagne
32