SlideShare a Scribd company logo
An Introduction to
threads
Presented by:
Zahra sadeghi
zahra sadeghi 2
history
 First: in late 60’s
 early 80’s : Unix community
 Windows 95 and OS/2
 Today: all operating systems have
multithreaded capability
zahra sadeghi 3
Terminology
 Thread:
 single sequence of execution
 independent path of execution
 Multiprogramming: Running multiple processes
concurrently
 Multithreading: Running multiple threads within one
process concurrently
 i.e: having several code executions within a
single process
zahra sadeghi 4
Process and thread
 A process is the "heaviest" unit of kernel
scheduling.
 process has its own memory area and data.
 A thread is the "lightest" unit of kernel
scheduling.
 the thread shares memory and data with the other
threads.
 A process/program,consists of many threads. (At
least one thread exists within each process.)
zahra sadeghi 5
Are threads actually needed!!!
 We are able to do the normal work with the
computer (like editing/saving a file) or drawing a
graphic and listening to music etc without getting
bothered with the print job.
 separate threads are executing all these tasks.
 the database or a web server interacts with a
number of users simultaneously.
 they maintain a separate thread for each user and
hence can maintain the state of all the users.
 If the program is run as one sequence then it is
possible that failure in some part of the program
will disrupt the functioning of the entire program.
 threads can execute independent of others
zahra sadeghi 6
drawbacks
 Is a Costly concept
 Many threads : less processor time
 memory : storing the context information of
each thread.
 Good designed program
zahra sadeghi 7
Multi_threading
 Each thread has its own run-time stack and
CPU state
 Two different threads can act on the same
object and same static fields concurrently
zahra sadeghi 8
example
zahra sadeghi 9
A thread control problem
multi-processor system:
 the operating system can allocate individual threads to the separate
processors, which thus fastens the execution of the program.
 the distribution of the threads on several processors is faster than
sharing time-slices on a single processor.
zahra sadeghi 10
Race Condition
 if shared data is accessed in an
unsynchronized manner
 Two threads are simultaneously reading or
modifying some shared data
 outcome :the order in which the
program's threads are allocated CPU time
zahra sadeghi 11
 On a single processor system,
threads can be run either in a preemptive
mode or in a cooperative mode.
threads
preemptive cooperative
zahra sadeghi 12
preemptive mode
 the operating system distributes the
processor time between the threads
 interrupts the threads at regular intervals
 The processor time given to each thread is
so small
 The switching between threads is so fast
that it appears as if all the threads are
running simultaneously.
zahra sadeghi 13
Cooperative mode
 each thread can control the CPU for as
long as it needs it.
 one thread can starve all the others
 Windows 3.x uses this kind of
implementation.
 A, B and C can be
considered as three
threads and are context
switched at the points
indicated by the small
circles.
zahra sadeghi 14
Implemntation of cooperative mode
 jmp_buf is defined in the ANSI C header file
setjmp.h.
 setjmp() : to save the execution environment
before switching out
 longjmp() : to switch to a place recorded in a
particular jump buffer.
 With this technique, we can implement a
non-preemptive threaded system with
minimal capability in about 100 lines!
 Note that a separate stack is required for each
executing function.
zahra sadeghi 15
Links & White Papers on Threads
 http://jamesthornton.com/linux/FAQ/Thre
ads-
 FAQ/ThreadLibs.html
 http://linuxdevices.com/articles/AT675369
9732.html
 http://www.gridbus.org/~raj/asc98.html

More Related Content

What's hot

Thread
ThreadThread
Thread
Mohd Arif
 
Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)
sonuu__
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
Sonali Chauhan
 
Thread
ThreadThread
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
anoopkrishna2
 
Multithreading
Multithreading Multithreading
Multithreading
WafaQKhan
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
tech2click
 
4 threads
4 threads4 threads
4 threads
Dr. Loganathan R
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
meet darji
 
OS_Ch5
OS_Ch5OS_Ch5
Operating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingOperating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programming
guesta40f80
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
Prakhar Maurya
 
Multithreading
MultithreadingMultithreading
Multithreading
A B Shinde
 
Hardware Multi-Threading
Hardware Multi-ThreadingHardware Multi-Threading
Hardware Multi-Threading
babuece
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating Systems
Nitish Gulati
 
Lecture24 Multiprocessor
Lecture24 MultiprocessorLecture24 Multiprocessor
Lecture24 Multiprocessor
allankliu
 
Multiple processor (ppt 2010)
Multiple processor (ppt 2010)Multiple processor (ppt 2010)
Multiple processor (ppt 2010)
Arth Ramada
 
Cache coherence
Cache coherenceCache coherence
Cache coherence
Employee
 
Processes and threads
Processes and threadsProcesses and threads
Cache coherence problem and its solutions
Cache coherence problem and its solutionsCache coherence problem and its solutions
Cache coherence problem and its solutions
Majid Saleem
 

What's hot (20)

Thread
ThreadThread
Thread
 
Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)Operating system: threads(mulithreading,benefits of threads, types of thread)
Operating system: threads(mulithreading,benefits of threads, types of thread)
 
Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
 
Thread
ThreadThread
Thread
 
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
 
Multithreading
Multithreading Multithreading
Multithreading
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
 
4 threads
4 threads4 threads
4 threads
 
Threads .ppt
Threads .pptThreads .ppt
Threads .ppt
 
OS_Ch5
OS_Ch5OS_Ch5
OS_Ch5
 
Operating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programmingOperating System Chapter 4 Multithreaded programming
Operating System Chapter 4 Multithreaded programming
 
Threads (operating System)
Threads (operating System)Threads (operating System)
Threads (operating System)
 
Multithreading
MultithreadingMultithreading
Multithreading
 
Hardware Multi-Threading
Hardware Multi-ThreadingHardware Multi-Threading
Hardware Multi-Threading
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating Systems
 
Lecture24 Multiprocessor
Lecture24 MultiprocessorLecture24 Multiprocessor
Lecture24 Multiprocessor
 
Multiple processor (ppt 2010)
Multiple processor (ppt 2010)Multiple processor (ppt 2010)
Multiple processor (ppt 2010)
 
Cache coherence
Cache coherenceCache coherence
Cache coherence
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Cache coherence problem and its solutions
Cache coherence problem and its solutionsCache coherence problem and its solutions
Cache coherence problem and its solutions
 

Viewers also liked

Parcticas
ParcticasParcticas
Parcticas
Abel Rivera
 
BSI 9001 Certificate
BSI 9001 CertificateBSI 9001 Certificate
BSI 9001 Certificate
James Clayden
 
Practicas de powerpoint
Practicas de powerpoint Practicas de powerpoint
Practicas de powerpoint
Abel Rivera
 
Design hybrid micropower system in mistah village using homer model
Design hybrid micropower system in mistah village using homer modelDesign hybrid micropower system in mistah village using homer model
Design hybrid micropower system in mistah village using homer model
IAEME Publication
 
Comunidades en medellín – barrio castilla
Comunidades en medellín – barrio castillaComunidades en medellín – barrio castilla
Comunidades en medellín – barrio castilla
rutaimedellin
 
16-bit microprocessors
16-bit microprocessors16-bit microprocessors
16-bit microprocessors
Zahra Sadeghi
 
Holistic Counseling
Holistic CounselingHolistic Counseling
Holistic Counseling
Christina Mueller
 
Authentic Leadership
Authentic LeadershipAuthentic Leadership
Authentic Leadership
Christina Mueller
 
Easilens healthcare-computers-limited
Easilens healthcare-computers-limitedEasilens healthcare-computers-limited
Easilens healthcare-computers-limited
Easilens Healthcare Computers Limited
 
Experiential Learning Overview MTSU EMC
Experiential Learning Overview MTSU EMCExperiential Learning Overview MTSU EMC
Experiential Learning Overview MTSU EMC
Middle Tennessee State University
 
Adonis y Venus
Adonis y VenusAdonis y Venus
Adonis y Venus
lupemm
 
201607 03 - odoo 8.0
201607 03 - odoo 8.0201607 03 - odoo 8.0
201607 03 - odoo 8.0
Associazione Odoo Italia
 
Tyrosine kinase report
Tyrosine kinase reportTyrosine kinase report
Tyrosine kinase report
jinx11
 

Viewers also liked (14)

Parcticas
ParcticasParcticas
Parcticas
 
BSI 9001 Certificate
BSI 9001 CertificateBSI 9001 Certificate
BSI 9001 Certificate
 
Practicas de powerpoint
Practicas de powerpoint Practicas de powerpoint
Practicas de powerpoint
 
Design hybrid micropower system in mistah village using homer model
Design hybrid micropower system in mistah village using homer modelDesign hybrid micropower system in mistah village using homer model
Design hybrid micropower system in mistah village using homer model
 
Comunidades en medellín – barrio castilla
Comunidades en medellín – barrio castillaComunidades en medellín – barrio castilla
Comunidades en medellín – barrio castilla
 
16-bit microprocessors
16-bit microprocessors16-bit microprocessors
16-bit microprocessors
 
Holistic Counseling
Holistic CounselingHolistic Counseling
Holistic Counseling
 
Authentic Leadership
Authentic LeadershipAuthentic Leadership
Authentic Leadership
 
Sb diet-flyer
Sb diet-flyerSb diet-flyer
Sb diet-flyer
 
Easilens healthcare-computers-limited
Easilens healthcare-computers-limitedEasilens healthcare-computers-limited
Easilens healthcare-computers-limited
 
Experiential Learning Overview MTSU EMC
Experiential Learning Overview MTSU EMCExperiential Learning Overview MTSU EMC
Experiential Learning Overview MTSU EMC
 
Adonis y Venus
Adonis y VenusAdonis y Venus
Adonis y Venus
 
201607 03 - odoo 8.0
201607 03 - odoo 8.0201607 03 - odoo 8.0
201607 03 - odoo 8.0
 
Tyrosine kinase report
Tyrosine kinase reportTyrosine kinase report
Tyrosine kinase report
 

Similar to An Introduction to threads

4.Process.ppt
4.Process.ppt4.Process.ppt
4.Process.ppt
AkfeteAssefa
 
Wiki 2
Wiki 2Wiki 2
Wiki 2
Sid Hegde
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Raghu nath
 
Threads
ThreadsThreads
Threads
SURBHI SAROHA
 
Assignment-01.pptx
Assignment-01.pptxAssignment-01.pptx
Assignment-01.pptx
HaiderZaman45
 
Topic 4- processes.pptx
Topic 4- processes.pptxTopic 4- processes.pptx
Topic 4- processes.pptx
DanishMahmood23
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
AnyapuPranav
 
Chapter04 new
Chapter04 newChapter04 new
Chapter04 new
vmummaneni
 
Os
OsOs
Threads
ThreadsThreads
Operating Systems R20 Unit 2.pptx
Operating Systems R20 Unit 2.pptxOperating Systems R20 Unit 2.pptx
Operating Systems R20 Unit 2.pptx
Prudhvi668506
 
Threading.pptx
Threading.pptxThreading.pptx
Threading.pptx
BalasundaramSr
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
Ra'Fat Al-Msie'deen
 
Concurrency in java
Concurrency in javaConcurrency in java
Concurrency in java
Saquib Sajid
 
Shared memory Parallelism (NOTES)
Shared memory Parallelism (NOTES)Shared memory Parallelism (NOTES)
Shared memory Parallelism (NOTES)
Subhajit Sahu
 
dos slide share.pptx
dos slide share.pptxdos slide share.pptx
dos slide share.pptx
NagaVarthini
 
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating SystemProcess, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
LieYah Daliah
 
Lecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxLecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptx
Amanuelmergia
 
Multi t hreading_14_10
Multi t hreading_14_10Multi t hreading_14_10
Multi t hreading_14_10
Minal Maniar
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
bleh23
 

Similar to An Introduction to threads (20)

4.Process.ppt
4.Process.ppt4.Process.ppt
4.Process.ppt
 
Wiki 2
Wiki 2Wiki 2
Wiki 2
 
Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
 
Threads
ThreadsThreads
Threads
 
Assignment-01.pptx
Assignment-01.pptxAssignment-01.pptx
Assignment-01.pptx
 
Topic 4- processes.pptx
Topic 4- processes.pptxTopic 4- processes.pptx
Topic 4- processes.pptx
 
Multi threaded programming
Multi threaded programmingMulti threaded programming
Multi threaded programming
 
Chapter04 new
Chapter04 newChapter04 new
Chapter04 new
 
Os
OsOs
Os
 
Threads
ThreadsThreads
Threads
 
Operating Systems R20 Unit 2.pptx
Operating Systems R20 Unit 2.pptxOperating Systems R20 Unit 2.pptx
Operating Systems R20 Unit 2.pptx
 
Threading.pptx
Threading.pptxThreading.pptx
Threading.pptx
 
Operating Systems - "Chapter 4: Multithreaded Programming"
Operating Systems - "Chapter 4:  Multithreaded Programming"Operating Systems - "Chapter 4:  Multithreaded Programming"
Operating Systems - "Chapter 4: Multithreaded Programming"
 
Concurrency in java
Concurrency in javaConcurrency in java
Concurrency in java
 
Shared memory Parallelism (NOTES)
Shared memory Parallelism (NOTES)Shared memory Parallelism (NOTES)
Shared memory Parallelism (NOTES)
 
dos slide share.pptx
dos slide share.pptxdos slide share.pptx
dos slide share.pptx
 
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating SystemProcess, Threads, Symmetric Multiprocessing and Microkernels in Operating System
Process, Threads, Symmetric Multiprocessing and Microkernels in Operating System
 
Lecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxLecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptx
 
Multi t hreading_14_10
Multi t hreading_14_10Multi t hreading_14_10
Multi t hreading_14_10
 
OS Module-2.pptx
OS Module-2.pptxOS Module-2.pptx
OS Module-2.pptx
 

More from Zahra Sadeghi

Maritime Anomaly Detection
Maritime Anomaly DetectionMaritime Anomaly Detection
Maritime Anomaly Detection
Zahra Sadeghi
 
Quality Assurance in Modern Software Development
Quality Assurance in Modern Software DevelopmentQuality Assurance in Modern Software Development
Quality Assurance in Modern Software Development
Zahra Sadeghi
 
Attention mechanism in brain and deep neural network
Attention mechanism in brain and deep neural networkAttention mechanism in brain and deep neural network
Attention mechanism in brain and deep neural network
Zahra Sadeghi
 
Perception, representation, structure, and recognition
Perception, representation, structure, and recognitionPerception, representation, structure, and recognition
Perception, representation, structure, and recognition
Zahra Sadeghi
 
An introduction to Autonomous mobile robots
An introduction to Autonomous mobile robotsAn introduction to Autonomous mobile robots
An introduction to Autonomous mobile robots
Zahra Sadeghi
 
Bluetooth Technoloty
Bluetooth TechnolotyBluetooth Technoloty
Bluetooth Technoloty
Zahra Sadeghi
 
Self Organization Map
Self Organization MapSelf Organization Map
Self Organization Map
Zahra Sadeghi
 
A survey on ant colony clustering papers
A survey on ant colony clustering papersA survey on ant colony clustering papers
A survey on ant colony clustering papers
Zahra Sadeghi
 
Pittssburgh approach
Pittssburgh approachPittssburgh approach
Pittssburgh approach
Zahra Sadeghi
 
Cerebellar Model Articulation Controller
Cerebellar Model Articulation ControllerCerebellar Model Articulation Controller
Cerebellar Model Articulation Controller
Zahra Sadeghi
 
Semantic Search with Semantic Web
Semantic Search with Semantic WebSemantic Search with Semantic Web
Semantic Search with Semantic Web
Zahra Sadeghi
 
Interval programming
Interval programming Interval programming
Interval programming
Zahra Sadeghi
 
Logic converter
Logic converterLogic converter
Logic converter
Zahra Sadeghi
 
Ms dos boot process
Ms dos boot process Ms dos boot process
Ms dos boot process
Zahra Sadeghi
 
An intoroduction to Multimedia
An intoroduction to MultimediaAn intoroduction to Multimedia
An intoroduction to Multimedia
Zahra Sadeghi
 
Penalty function
Penalty function Penalty function
Penalty function
Zahra Sadeghi
 
Neural networks
Neural networksNeural networks
Neural networks
Zahra Sadeghi
 
Parametric and non parametric classifiers
Parametric and non parametric classifiersParametric and non parametric classifiers
Parametric and non parametric classifiers
Zahra Sadeghi
 
sampling
samplingsampling
sampling
Zahra Sadeghi
 
Jack rental-car-problem
Jack rental-car-problemJack rental-car-problem
Jack rental-car-problem
Zahra Sadeghi
 

More from Zahra Sadeghi (20)

Maritime Anomaly Detection
Maritime Anomaly DetectionMaritime Anomaly Detection
Maritime Anomaly Detection
 
Quality Assurance in Modern Software Development
Quality Assurance in Modern Software DevelopmentQuality Assurance in Modern Software Development
Quality Assurance in Modern Software Development
 
Attention mechanism in brain and deep neural network
Attention mechanism in brain and deep neural networkAttention mechanism in brain and deep neural network
Attention mechanism in brain and deep neural network
 
Perception, representation, structure, and recognition
Perception, representation, structure, and recognitionPerception, representation, structure, and recognition
Perception, representation, structure, and recognition
 
An introduction to Autonomous mobile robots
An introduction to Autonomous mobile robotsAn introduction to Autonomous mobile robots
An introduction to Autonomous mobile robots
 
Bluetooth Technoloty
Bluetooth TechnolotyBluetooth Technoloty
Bluetooth Technoloty
 
Self Organization Map
Self Organization MapSelf Organization Map
Self Organization Map
 
A survey on ant colony clustering papers
A survey on ant colony clustering papersA survey on ant colony clustering papers
A survey on ant colony clustering papers
 
Pittssburgh approach
Pittssburgh approachPittssburgh approach
Pittssburgh approach
 
Cerebellar Model Articulation Controller
Cerebellar Model Articulation ControllerCerebellar Model Articulation Controller
Cerebellar Model Articulation Controller
 
Semantic Search with Semantic Web
Semantic Search with Semantic WebSemantic Search with Semantic Web
Semantic Search with Semantic Web
 
Interval programming
Interval programming Interval programming
Interval programming
 
Logic converter
Logic converterLogic converter
Logic converter
 
Ms dos boot process
Ms dos boot process Ms dos boot process
Ms dos boot process
 
An intoroduction to Multimedia
An intoroduction to MultimediaAn intoroduction to Multimedia
An intoroduction to Multimedia
 
Penalty function
Penalty function Penalty function
Penalty function
 
Neural networks
Neural networksNeural networks
Neural networks
 
Parametric and non parametric classifiers
Parametric and non parametric classifiersParametric and non parametric classifiers
Parametric and non parametric classifiers
 
sampling
samplingsampling
sampling
 
Jack rental-car-problem
Jack rental-car-problemJack rental-car-problem
Jack rental-car-problem
 

Recently uploaded

BIOTRANSFORMATION MECHANISM FOR OF STEROID
BIOTRANSFORMATION MECHANISM FOR OF STEROIDBIOTRANSFORMATION MECHANISM FOR OF STEROID
BIOTRANSFORMATION MECHANISM FOR OF STEROID
ShibsekharRoy1
 
Anti-Universe And Emergent Gravity and the Dark Universe
Anti-Universe And Emergent Gravity and the Dark UniverseAnti-Universe And Emergent Gravity and the Dark Universe
Anti-Universe And Emergent Gravity and the Dark Universe
Sérgio Sacani
 
JAMES WEBB STUDY THE MASSIVE BLACK HOLE SEEDS
JAMES WEBB STUDY THE MASSIVE BLACK HOLE SEEDSJAMES WEBB STUDY THE MASSIVE BLACK HOLE SEEDS
JAMES WEBB STUDY THE MASSIVE BLACK HOLE SEEDS
Sérgio Sacani
 
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
Advanced-Concepts-Team
 
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
hozt8xgk
 
GBSN - Biochemistry (Unit 6) Chemistry of Proteins
GBSN - Biochemistry (Unit 6) Chemistry of ProteinsGBSN - Biochemistry (Unit 6) Chemistry of Proteins
GBSN - Biochemistry (Unit 6) Chemistry of Proteins
Areesha Ahmad
 
Farming systems analysis: what have we learnt?.pptx
Farming systems analysis: what have we learnt?.pptxFarming systems analysis: what have we learnt?.pptx
Farming systems analysis: what have we learnt?.pptx
Frédéric Baudron
 
Summary Of transcription and Translation.pdf
Summary Of transcription and Translation.pdfSummary Of transcription and Translation.pdf
Summary Of transcription and Translation.pdf
vadgavevedant86
 
11.1 Role of physical biological in deterioration of grains.pdf
11.1 Role of physical biological in deterioration of grains.pdf11.1 Role of physical biological in deterioration of grains.pdf
11.1 Role of physical biological in deterioration of grains.pdf
PirithiRaju
 
TOPIC OF DISCUSSION: CENTRIFUGATION SLIDESHARE.pptx
TOPIC OF DISCUSSION: CENTRIFUGATION SLIDESHARE.pptxTOPIC OF DISCUSSION: CENTRIFUGATION SLIDESHARE.pptx
TOPIC OF DISCUSSION: CENTRIFUGATION SLIDESHARE.pptx
shubhijain836
 
Pests of Storage_Identification_Dr.UPR.pdf
Pests of Storage_Identification_Dr.UPR.pdfPests of Storage_Identification_Dr.UPR.pdf
Pests of Storage_Identification_Dr.UPR.pdf
PirithiRaju
 
AJAY KUMAR NIET GreNo Guava Project File.pdf
AJAY KUMAR NIET GreNo Guava Project File.pdfAJAY KUMAR NIET GreNo Guava Project File.pdf
AJAY KUMAR NIET GreNo Guava Project File.pdf
AJAY KUMAR
 
Alternate Wetting and Drying - Climate Smart Agriculture
Alternate Wetting and Drying - Climate Smart AgricultureAlternate Wetting and Drying - Climate Smart Agriculture
Alternate Wetting and Drying - Climate Smart Agriculture
International Food Policy Research Institute- South Asia Office
 
The cost of acquiring information by natural selection
The cost of acquiring information by natural selectionThe cost of acquiring information by natural selection
The cost of acquiring information by natural selection
Carl Bergstrom
 
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdfMending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Selcen Ozturkcan
 
2001_Book_HumanChromosomes - Genéticapdf
2001_Book_HumanChromosomes - Genéticapdf2001_Book_HumanChromosomes - Genéticapdf
2001_Book_HumanChromosomes - Genéticapdf
lucianamillenium
 
Gadgets for management of stored product pests_Dr.UPR.pdf
Gadgets for management of stored product pests_Dr.UPR.pdfGadgets for management of stored product pests_Dr.UPR.pdf
Gadgets for management of stored product pests_Dr.UPR.pdf
PirithiRaju
 
SDSS1335+0728: The awakening of a ∼ 106M⊙ black hole⋆
SDSS1335+0728: The awakening of a ∼ 106M⊙ black hole⋆SDSS1335+0728: The awakening of a ∼ 106M⊙ black hole⋆
SDSS1335+0728: The awakening of a ∼ 106M⊙ black hole⋆
Sérgio Sacani
 
Microbiology of Central Nervous System INFECTIONS.pdf
Microbiology of Central Nervous System INFECTIONS.pdfMicrobiology of Central Nervous System INFECTIONS.pdf
Microbiology of Central Nervous System INFECTIONS.pdf
sammy700571
 
Authoring a personal GPT for your research and practice: How we created the Q...
Authoring a personal GPT for your research and practice: How we created the Q...Authoring a personal GPT for your research and practice: How we created the Q...
Authoring a personal GPT for your research and practice: How we created the Q...
Leonel Morgado
 

Recently uploaded (20)

BIOTRANSFORMATION MECHANISM FOR OF STEROID
BIOTRANSFORMATION MECHANISM FOR OF STEROIDBIOTRANSFORMATION MECHANISM FOR OF STEROID
BIOTRANSFORMATION MECHANISM FOR OF STEROID
 
Anti-Universe And Emergent Gravity and the Dark Universe
Anti-Universe And Emergent Gravity and the Dark UniverseAnti-Universe And Emergent Gravity and the Dark Universe
Anti-Universe And Emergent Gravity and the Dark Universe
 
JAMES WEBB STUDY THE MASSIVE BLACK HOLE SEEDS
JAMES WEBB STUDY THE MASSIVE BLACK HOLE SEEDSJAMES WEBB STUDY THE MASSIVE BLACK HOLE SEEDS
JAMES WEBB STUDY THE MASSIVE BLACK HOLE SEEDS
 
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
ESA/ACT Science Coffee: Diego Blas - Gravitational wave detection with orbita...
 
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
快速办理(UAM毕业证书)马德里自治大学毕业证学位证一模一样
 
GBSN - Biochemistry (Unit 6) Chemistry of Proteins
GBSN - Biochemistry (Unit 6) Chemistry of ProteinsGBSN - Biochemistry (Unit 6) Chemistry of Proteins
GBSN - Biochemistry (Unit 6) Chemistry of Proteins
 
Farming systems analysis: what have we learnt?.pptx
Farming systems analysis: what have we learnt?.pptxFarming systems analysis: what have we learnt?.pptx
Farming systems analysis: what have we learnt?.pptx
 
Summary Of transcription and Translation.pdf
Summary Of transcription and Translation.pdfSummary Of transcription and Translation.pdf
Summary Of transcription and Translation.pdf
 
11.1 Role of physical biological in deterioration of grains.pdf
11.1 Role of physical biological in deterioration of grains.pdf11.1 Role of physical biological in deterioration of grains.pdf
11.1 Role of physical biological in deterioration of grains.pdf
 
TOPIC OF DISCUSSION: CENTRIFUGATION SLIDESHARE.pptx
TOPIC OF DISCUSSION: CENTRIFUGATION SLIDESHARE.pptxTOPIC OF DISCUSSION: CENTRIFUGATION SLIDESHARE.pptx
TOPIC OF DISCUSSION: CENTRIFUGATION SLIDESHARE.pptx
 
Pests of Storage_Identification_Dr.UPR.pdf
Pests of Storage_Identification_Dr.UPR.pdfPests of Storage_Identification_Dr.UPR.pdf
Pests of Storage_Identification_Dr.UPR.pdf
 
AJAY KUMAR NIET GreNo Guava Project File.pdf
AJAY KUMAR NIET GreNo Guava Project File.pdfAJAY KUMAR NIET GreNo Guava Project File.pdf
AJAY KUMAR NIET GreNo Guava Project File.pdf
 
Alternate Wetting and Drying - Climate Smart Agriculture
Alternate Wetting and Drying - Climate Smart AgricultureAlternate Wetting and Drying - Climate Smart Agriculture
Alternate Wetting and Drying - Climate Smart Agriculture
 
The cost of acquiring information by natural selection
The cost of acquiring information by natural selectionThe cost of acquiring information by natural selection
The cost of acquiring information by natural selection
 
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdfMending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
Mending Clothing to Support Sustainable Fashion_CIMaR 2024.pdf
 
2001_Book_HumanChromosomes - Genéticapdf
2001_Book_HumanChromosomes - Genéticapdf2001_Book_HumanChromosomes - Genéticapdf
2001_Book_HumanChromosomes - Genéticapdf
 
Gadgets for management of stored product pests_Dr.UPR.pdf
Gadgets for management of stored product pests_Dr.UPR.pdfGadgets for management of stored product pests_Dr.UPR.pdf
Gadgets for management of stored product pests_Dr.UPR.pdf
 
SDSS1335+0728: The awakening of a ∼ 106M⊙ black hole⋆
SDSS1335+0728: The awakening of a ∼ 106M⊙ black hole⋆SDSS1335+0728: The awakening of a ∼ 106M⊙ black hole⋆
SDSS1335+0728: The awakening of a ∼ 106M⊙ black hole⋆
 
Microbiology of Central Nervous System INFECTIONS.pdf
Microbiology of Central Nervous System INFECTIONS.pdfMicrobiology of Central Nervous System INFECTIONS.pdf
Microbiology of Central Nervous System INFECTIONS.pdf
 
Authoring a personal GPT for your research and practice: How we created the Q...
Authoring a personal GPT for your research and practice: How we created the Q...Authoring a personal GPT for your research and practice: How we created the Q...
Authoring a personal GPT for your research and practice: How we created the Q...
 

An Introduction to threads

  • 2. zahra sadeghi 2 history  First: in late 60’s  early 80’s : Unix community  Windows 95 and OS/2  Today: all operating systems have multithreaded capability
  • 3. zahra sadeghi 3 Terminology  Thread:  single sequence of execution  independent path of execution  Multiprogramming: Running multiple processes concurrently  Multithreading: Running multiple threads within one process concurrently  i.e: having several code executions within a single process
  • 4. zahra sadeghi 4 Process and thread  A process is the "heaviest" unit of kernel scheduling.  process has its own memory area and data.  A thread is the "lightest" unit of kernel scheduling.  the thread shares memory and data with the other threads.  A process/program,consists of many threads. (At least one thread exists within each process.)
  • 5. zahra sadeghi 5 Are threads actually needed!!!  We are able to do the normal work with the computer (like editing/saving a file) or drawing a graphic and listening to music etc without getting bothered with the print job.  separate threads are executing all these tasks.  the database or a web server interacts with a number of users simultaneously.  they maintain a separate thread for each user and hence can maintain the state of all the users.  If the program is run as one sequence then it is possible that failure in some part of the program will disrupt the functioning of the entire program.  threads can execute independent of others
  • 6. zahra sadeghi 6 drawbacks  Is a Costly concept  Many threads : less processor time  memory : storing the context information of each thread.  Good designed program
  • 7. zahra sadeghi 7 Multi_threading  Each thread has its own run-time stack and CPU state  Two different threads can act on the same object and same static fields concurrently
  • 9. zahra sadeghi 9 A thread control problem multi-processor system:  the operating system can allocate individual threads to the separate processors, which thus fastens the execution of the program.  the distribution of the threads on several processors is faster than sharing time-slices on a single processor.
  • 10. zahra sadeghi 10 Race Condition  if shared data is accessed in an unsynchronized manner  Two threads are simultaneously reading or modifying some shared data  outcome :the order in which the program's threads are allocated CPU time
  • 11. zahra sadeghi 11  On a single processor system, threads can be run either in a preemptive mode or in a cooperative mode. threads preemptive cooperative
  • 12. zahra sadeghi 12 preemptive mode  the operating system distributes the processor time between the threads  interrupts the threads at regular intervals  The processor time given to each thread is so small  The switching between threads is so fast that it appears as if all the threads are running simultaneously.
  • 13. zahra sadeghi 13 Cooperative mode  each thread can control the CPU for as long as it needs it.  one thread can starve all the others  Windows 3.x uses this kind of implementation.  A, B and C can be considered as three threads and are context switched at the points indicated by the small circles.
  • 14. zahra sadeghi 14 Implemntation of cooperative mode  jmp_buf is defined in the ANSI C header file setjmp.h.  setjmp() : to save the execution environment before switching out  longjmp() : to switch to a place recorded in a particular jump buffer.  With this technique, we can implement a non-preemptive threaded system with minimal capability in about 100 lines!  Note that a separate stack is required for each executing function.
  • 15. zahra sadeghi 15 Links & White Papers on Threads  http://jamesthornton.com/linux/FAQ/Thre ads-  FAQ/ThreadLibs.html  http://linuxdevices.com/articles/AT675369 9732.html  http://www.gridbus.org/~raj/asc98.html