SlideShare a Scribd company logo
1 of 15
Download to read offline
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

Operating System-Threads-Galvin
Operating System-Threads-GalvinOperating System-Threads-Galvin
Operating System-Threads-Galvin
Sonali Chauhan
 
Multithreading models
Multithreading modelsMultithreading models
Multithreading models
anoopkrishna2
 
Operating System 4
Operating System 4Operating System 4
Operating System 4
tech2click
 
Thread scheduling in Operating Systems
Thread scheduling in Operating SystemsThread scheduling in Operating Systems
Thread scheduling in Operating Systems
Nitish Gulati
 
Cache coherence
Cache coherenceCache coherence
Cache coherence
Employee
 

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 (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

Multithreading in java
Multithreading in javaMultithreading in java
Multithreading in java
Raghu nath
 
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
 
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

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

Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Sérgio Sacani
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdf
PirithiRaju
 
Conjugation, transduction and transformation
Conjugation, transduction and transformationConjugation, transduction and transformation
Conjugation, transduction and transformation
Areesha Ahmad
 
Introduction,importance and scope of horticulture.pptx
Introduction,importance and scope of horticulture.pptxIntroduction,importance and scope of horticulture.pptx
Introduction,importance and scope of horticulture.pptx
Bhagirath Gogikar
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
ssuser79fe74
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
PirithiRaju
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
Areesha Ahmad
 
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
dkNET
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
RizalinePalanog2
 

Recently uploaded (20)

Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 bAsymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
Asymmetry in the atmosphere of the ultra-hot Jupiter WASP-76 b
 
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and SpectrometryFAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
FAIRSpectra - Enabling the FAIRification of Spectroscopy and Spectrometry
 
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 60009654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
9654467111 Call Girls In Raj Nagar Delhi Short 1500 Night 6000
 
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
9999266834 Call Girls In Noida Sector 22 (Delhi) Call Girl Service
 
Clean In Place(CIP).pptx .
Clean In Place(CIP).pptx                 .Clean In Place(CIP).pptx                 .
Clean In Place(CIP).pptx .
 
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
High Profile 🔝 8250077686 📞 Call Girls Service in GTB Nagar🍑
 
Pests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdfPests of mustard_Identification_Management_Dr.UPR.pdf
Pests of mustard_Identification_Management_Dr.UPR.pdf
 
Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...
Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...
Dopamine neurotransmitter determination using graphite sheet- graphene nano-s...
 
Conjugation, transduction and transformation
Conjugation, transduction and transformationConjugation, transduction and transformation
Conjugation, transduction and transformation
 
Introduction,importance and scope of horticulture.pptx
Introduction,importance and scope of horticulture.pptxIntroduction,importance and scope of horticulture.pptx
Introduction,importance and scope of horticulture.pptx
 
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
Chemical Tests; flame test, positive and negative ions test Edexcel Internati...
 
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdfPests of cotton_Sucking_Pests_Dr.UPR.pdf
Pests of cotton_Sucking_Pests_Dr.UPR.pdf
 
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceuticsPulmonary drug delivery system M.pharm -2nd sem P'ceutics
Pulmonary drug delivery system M.pharm -2nd sem P'ceutics
 
Bacterial Identification and Classifications
Bacterial Identification and ClassificationsBacterial Identification and Classifications
Bacterial Identification and Classifications
 
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
Vip profile Call Girls In Lonavala 9748763073 For Genuine Sex Service At Just...
 
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
dkNET Webinar "Texera: A Scalable Cloud Computing Platform for Sharing Data a...
 
GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)GBSN - Biochemistry (Unit 1)
GBSN - Biochemistry (Unit 1)
 
GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)GBSN - Microbiology (Unit 2)
GBSN - Microbiology (Unit 2)
 
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptxSCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
SCIENCE-4-QUARTER4-WEEK-4-PPT-1 (1).pptx
 
CELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdfCELL -Structural and Functional unit of life.pdf
CELL -Structural and Functional unit of life.pdf
 

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