SlideShare a Scribd company logo
INTRODUCTION TO THREADS
PREVIOUS SESSION
• Program vs Process
• Process states
• Process control block
• Process creation through fork()
• Exec(), wait and exit() system calls
• Zombie and orphan process
AGENDA
• Interprocess communication
• What is a thread
• Thread vs process
• Multithreading and multiprocessing
• Multithreading models
• Challenges with multithreading
INTERVIEW QUESTIONS
• What are similarities and differences between a process and a
thread?
• What is IPC? Give some examples of IPC
• Why process coordination is necessary in OS?
• What are advantages and disadvantages of using shared memory and
IPC?
• What is multi-tasking, multi-programming, multithreading and
multiprocessing?
• What are the challenges faced in multithreading programs?
• Difference between chrome and firefox in terms of multiprocessing
and multithreading?
• What is the difference between named pipe and unnamed pipe?
• What are the benefits of multithreading?
INTERPROCESS COMMUNICATION
• Independent vs cooperating process
• Does a process shares data with other process?
• Debugging becomes tough in cooperating processes.
• Why process cooperation is necessary?
Need for process cooperation
• Information sharing
• Computational speedup
• Modularity
• Convenience
• Detailed explanation: https://youtu.be/7jN8tgLqbFc
Models/Types of interprocess communication
• Shared memory
• A region of shared memory is first established
• Processes then share information by reading and writing to this shared space.
• Threads
• Message passing
• A link is established between two or more processes
• Messages are then shared on this link
• Detailed explanation: https://youtu.be/FCPUTFmAlIg
Threads in Operating System | Multithreading | Interprocess Communication
Shared memory vs Message Passing
Examples
• Shared memory is achieved using multithreading.
• Message passing examples
• Sockets
• Pipes
• Remote procedure calls
• Pipes
• Ordinary pipes
• Named pipes
Threads in Operating System | Multithreading | Interprocess Communication
PIPES
• Unnamed pipe
• ls | grep “hello”
• cat filename | grep “hello”
• Named pipe
• mkfifo <file name>
• Unnamed pipe can only be used to communicate between parent and child
processes.
• A named pipe exists on the file system.
• Named pipe can be used for communication over a network.
• Named pipe are bidirectional.
WHAT IS A THREAD
• A thread is a basic unit of CPU utlilization.
• A thread consists of:
• Thread ID
• Program counter
• Register sets
• Stack segment memory
• What does CPU needs to execute instructions?
• Registers
• Program counter
• Process is also a unit of CPU utilization, but not a basic unit.
• Detailed explanation - https://youtu.be/pYbBgA76wDg
What a thread shares with other threads?
• Code section memory
• Data segment memory
• Heap segment memory
• Open files
• Signals
• Linux has a unique implementation of threads. To the Linux kernel,
there is no concept of a thread. Linux implements all threads as
standard processes.
• Each thread has a unique process control block and appears to the
kernel as a normal process—threads just happen to share resources,
such as an address space, with other processes.
• Windows – explicit support for threads (lightweight process)
Threads implementation in Linux
• Normal fork()
• clone(SIGCHLD, 0);
• Thread implementation
• clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0);
Threads in Operating System | Multithreading | Interprocess Communication
THREAD VS PROCESS
PROCESS THREAD
Differences continued
Detailed explanation -
https://youtu.be/MwDccB9tvp0
MULTITHREADING
• Multiple threads within a process
• Should be supported by the hardware
• Concurrency vs parallelism
• Most applications are multithreaded today
• Browser – rendering + fetching
• Web server having multiple clients
• Word processor – displaying graphics + waiting for keystroke + spell
check
Benefits of multithreading
• Responsiveness – browser, word-processor
• Resource sharing – threads share the memory and resources by
default
• Economy – creating multiple processes is very costly.
• Scalability – increases the parallelism, web servers
Challenges
• Concurrency issues
• Multiple threads trying to update the resource at the same time.
• Leads to race condition
• How i++ is actually executed?
Initially i = 7, final value = 9 and two threads
incrementing i
Initial value = 7, final value = 8
MULTIPROCESSING
• Multiple processes within a process
• Using fork() to create multiple processes
• Process creation is time-consuming than creating threads.
• Process address space is not shared among processes.
CPUs, cores and hyperthreading
• A core is the basic computational unit of CPU. It has registers and all
other resources to execute a program.
• Processes -> threads
• CPU are the processor chips.
• Initially, a CPU had only one core.
• Today, dual-core or quad-core processors
• Hyper threading – allows a single core to run multiple threads. Some
hardware are duplicated.
Threads in Operating System | Multithreading | Interprocess Communication
When to use thread vs process
• Threads are faster
• Crashing one thread crashes other threads too.
• No security between threads – lead to race condition
• A tradeoff between speed vs reliability
• Chrome vs firefox – multiprocessing vs multithreading
• Web servers
• Word processor
• Computer games
Multiprogramming, multithreading,
multiprocessing
• Multiprogramming – ability of the system to run multiple programs
concurrently. Time sharing OS. Can happen even on a single core.
• Multitasking is similar to multiprogramming as we are able to do
multiple tasks at the same time.
• Multiprocessing – Using multiple cores for executing multiple
programs in parallel.
• Multithreading – Similar to multiprocessing but here the memory is
shared between threads. Usually, very fast.
Multithreading models
• How user threads are mapped to kernel threads?
• Not asked in any interviews
• 1:1 mapping
• N:N mapping
• M:N mapping
• Videos:
• https://youtu.be/lYNk1cNWCfc
• https://youtu.be/1Jij_qY2kp0
NEXT SESSION: PROCESS SCHEDULING
ALGORITHMS
Ad

More Related Content

What's hot (20)

17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
myrajendra
 
Multithreading
Multithreading Multithreading
Multithreading
WafaQKhan
 
Memory management
Memory managementMemory management
Memory management
CHANDERPRABHU JAIN COLLEGE OF HIGHER STUDIES & SCHOOL OF LAW
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
Mukesh Chinta
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
Adeel Rasheed
 
Distributed operating system(os)
Distributed operating system(os)Distributed operating system(os)
Distributed operating system(os)
Dinesh Modak
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
Rajapriya82
 
System calls
System callsSystem calls
System calls
Bernard Senam
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dos
vanamali_vanu
 
Lecture 3 threads
Lecture 3   threadsLecture 3   threads
Lecture 3 threads
Kumbirai Junior Muzavazi
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
Nishant Joshi
 
SCHEDULING ALGORITHMS
SCHEDULING ALGORITHMSSCHEDULING ALGORITHMS
SCHEDULING ALGORITHMS
Dhaval Sakhiya
 
Memory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memoryMemory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memory
Shivam Mitra
 
Distributed Operating System_1
Distributed Operating System_1Distributed Operating System_1
Distributed Operating System_1
Dr Sandeep Kumar Poonia
 
Presentation on Segmentation
Presentation on SegmentationPresentation on Segmentation
Presentation on Segmentation
Priyanka bisht
 
operating system structure
operating system structureoperating system structure
operating system structure
Waseem Ud Din Farooqui
 
What is Kernel, basic idea of kernel
What is Kernel, basic idea of kernelWhat is Kernel, basic idea of kernel
What is Kernel, basic idea of kernel
Neel Parikh
 
Context Switching
Context SwitchingContext Switching
Context Switching
franksvalli
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
Damian T. Gordon
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
Muhammad SiRaj Munir
 
17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria 17 cpu scheduling and scheduling criteria
17 cpu scheduling and scheduling criteria
myrajendra
 
Multithreading
Multithreading Multithreading
Multithreading
WafaQKhan
 
Operating systems system structures
Operating systems   system structuresOperating systems   system structures
Operating systems system structures
Mukesh Chinta
 
Inter Process Communication
Inter Process CommunicationInter Process Communication
Inter Process Communication
Adeel Rasheed
 
Distributed operating system(os)
Distributed operating system(os)Distributed operating system(os)
Distributed operating system(os)
Dinesh Modak
 
contiguous memory allocation.pptx
contiguous memory allocation.pptxcontiguous memory allocation.pptx
contiguous memory allocation.pptx
Rajapriya82
 
Design issues of dos
Design issues of dosDesign issues of dos
Design issues of dos
vanamali_vanu
 
Semophores and it's types
Semophores and it's typesSemophores and it's types
Semophores and it's types
Nishant Joshi
 
Memory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memoryMemory management in operating system | Paging | Virtual memory
Memory management in operating system | Paging | Virtual memory
Shivam Mitra
 
Presentation on Segmentation
Presentation on SegmentationPresentation on Segmentation
Presentation on Segmentation
Priyanka bisht
 
What is Kernel, basic idea of kernel
What is Kernel, basic idea of kernelWhat is Kernel, basic idea of kernel
What is Kernel, basic idea of kernel
Neel Parikh
 
Context Switching
Context SwitchingContext Switching
Context Switching
franksvalli
 
Operating Systems: Process Scheduling
Operating Systems: Process SchedulingOperating Systems: Process Scheduling
Operating Systems: Process Scheduling
Damian T. Gordon
 
Segmentation in Operating Systems.
Segmentation in Operating Systems.Segmentation in Operating Systems.
Segmentation in Operating Systems.
Muhammad SiRaj Munir
 

Similar to Threads in Operating System | Multithreading | Interprocess Communication (20)

Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentation
chnrketan
 
Thread
ThreadThread
Thread
Syed Zaid Irshad
 
Os lectures
Os lecturesOs lectures
Os lectures
Adnan Ghafoor
 
Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3
AbdullahMunir32
 
Lecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxLecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptx
Amanuelmergia
 
Gpgpu intro
Gpgpu introGpgpu intro
Gpgpu intro
Dominik Seifert
 
Threads lecture slides for operating systems
Threads lecture slides for operating systemsThreads lecture slides for operating systems
Threads lecture slides for operating systems
amirtarek401
 
Operating Systems & Applications
Operating Systems & ApplicationsOperating Systems & Applications
Operating Systems & Applications
Maulen Bale
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptx
LECO9
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptx
SKUP1
 
2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback
Jeff Squyres
 
Ch4 threads
Ch4   threadsCh4   threads
Ch4 threads
Welly Dian Astika
 
Thread
ThreadThread
Thread
sajidhuseyin
 
Thread
ThreadThread
Thread
Sajid Hussain
 
EuroMPI 2013 presentation: McMPI
EuroMPI 2013 presentation: McMPIEuroMPI 2013 presentation: McMPI
EuroMPI 2013 presentation: McMPI
Dan Holmes
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
Elizabeth Smith
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
Elizabeth Smith
 
Why Play Framework is fast
Why Play Framework is fastWhy Play Framework is fast
Why Play Framework is fast
Legacy Typesafe (now Lightbend)
 
15 threads
15 threads15 threads
15 threads
myrajendra
 
JavaScript Event Loop
JavaScript Event LoopJavaScript Event Loop
JavaScript Event Loop
Thomas Hunter II
 
Chapter -2 operating system presentation
Chapter -2 operating system presentationChapter -2 operating system presentation
Chapter -2 operating system presentation
chnrketan
 
Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3Parallel and Distributed Computing chapter 3
Parallel and Distributed Computing chapter 3
AbdullahMunir32
 
Lecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptxLecture 3- Threads (1).pptx
Lecture 3- Threads (1).pptx
Amanuelmergia
 
Threads lecture slides for operating systems
Threads lecture slides for operating systemsThreads lecture slides for operating systems
Threads lecture slides for operating systems
amirtarek401
 
Operating Systems & Applications
Operating Systems & ApplicationsOperating Systems & Applications
Operating Systems & Applications
Maulen Bale
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptx
LECO9
 
Processes, Threads.pptx
Processes, Threads.pptxProcesses, Threads.pptx
Processes, Threads.pptx
SKUP1
 
2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback2014 01-21-mpi-community-feedback
2014 01-21-mpi-community-feedback
Jeff Squyres
 
EuroMPI 2013 presentation: McMPI
EuroMPI 2013 presentation: McMPIEuroMPI 2013 presentation: McMPI
EuroMPI 2013 presentation: McMPI
Dan Holmes
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
Elizabeth Smith
 
Taming the resource tiger
Taming the resource tigerTaming the resource tiger
Taming the resource tiger
Elizabeth Smith
 
Ad

More from Shivam Mitra (16)

Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE Interviews
Shivam Mitra
 
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesPART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
Shivam Mitra
 
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With ExamplesPART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With Examples
Shivam Mitra
 
PART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With ExamplesPART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With Examples
Shivam Mitra
 
PART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesPART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With Examples
Shivam Mitra
 
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesPART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With Examples
Shivam Mitra
 
PART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesPART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With Examples
Shivam Mitra
 
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With ExamplesPART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With Examples
Shivam Mitra
 
PART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonPART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn python
Shivam Mitra
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonPART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in Python
Shivam Mitra
 
Part 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsPart 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to Lists
Shivam Mitra
 
What is Internet and How it Works
What is Internet and How it WorksWhat is Internet and How it Works
What is Internet and How it Works
Shivam Mitra
 
OSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackOSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol Stack
Shivam Mitra
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock Market
Shivam Mitra
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liability
Shivam Mitra
 
Pycricbuzz - a python library to fetch live cricket scores
Pycricbuzz -  a python library to fetch live cricket scoresPycricbuzz -  a python library to fetch live cricket scores
Pycricbuzz - a python library to fetch live cricket scores
Shivam Mitra
 
Preparing for SRE Interviews
Preparing for SRE InterviewsPreparing for SRE Interviews
Preparing for SRE Interviews
Shivam Mitra
 
PART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With ExamplesPART 4 - Python Tutorial | If Else In Python With Examples
PART 4 - Python Tutorial | If Else In Python With Examples
Shivam Mitra
 
PART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With ExamplesPART 3 - Python Tutorial | For Loop In Python With Examples
PART 3 - Python Tutorial | For Loop In Python With Examples
Shivam Mitra
 
PART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With ExamplesPART 9 - Python Tutorial | While Loop In Python With Examples
PART 9 - Python Tutorial | While Loop In Python With Examples
Shivam Mitra
 
PART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With ExamplesPART 8 - Python Tutorial | User Input In Python With Examples
PART 8 - Python Tutorial | User Input In Python With Examples
Shivam Mitra
 
PART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With ExamplesPART 6 - Python Tutorial | Tuples In Python With Examples
PART 6 - Python Tutorial | Tuples In Python With Examples
Shivam Mitra
 
PART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With ExamplesPART 10 - Python Tutorial | Functions In Python With Examples
PART 10 - Python Tutorial | Functions In Python With Examples
Shivam Mitra
 
PART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With ExamplesPART 7 - Python Tutorial | Dictionaries In Python With Examples
PART 7 - Python Tutorial | Dictionaries In Python With Examples
Shivam Mitra
 
PART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn pythonPART 0 - Python Tutorial | Why should you learn python
PART 0 - Python Tutorial | Why should you learn python
Shivam Mitra
 
PART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in PythonPART 1 - Python Tutorial | Variables and Data Types in Python
PART 1 - Python Tutorial | Variables and Data Types in Python
Shivam Mitra
 
Part 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to ListsPart 2 - Python Tutorial | Introduction to Lists
Part 2 - Python Tutorial | Introduction to Lists
Shivam Mitra
 
What is Internet and How it Works
What is Internet and How it WorksWhat is Internet and How it Works
What is Internet and How it Works
Shivam Mitra
 
OSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol StackOSI Model Layers and Internet Protocol Stack
OSI Model Layers and Internet Protocol Stack
Shivam Mitra
 
Basics of Stock Market
Basics of Stock MarketBasics of Stock Market
Basics of Stock Market
Shivam Mitra
 
Assets vs liability
Assets vs liabilityAssets vs liability
Assets vs liability
Shivam Mitra
 
Pycricbuzz - a python library to fetch live cricket scores
Pycricbuzz -  a python library to fetch live cricket scoresPycricbuzz -  a python library to fetch live cricket scores
Pycricbuzz - a python library to fetch live cricket scores
Shivam Mitra
 
Ad

Recently uploaded (20)

Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Structural Response of Reinforced Self-Compacting Concrete Deep Beam Using Fi...
Journal of Soft Computing in Civil Engineering
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
The Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLabThe Gaussian Process Modeling Module in UQLab
The Gaussian Process Modeling Module in UQLab
Journal of Soft Computing in Civil Engineering
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Process Parameter Optimization for Minimizing Springback in Cold Drawing Proc...
Journal of Soft Computing in Civil Engineering
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 
Metal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistryMetal alkyne complexes.pptx in chemistry
Metal alkyne complexes.pptx in chemistry
mee23nu
 
Oil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdfOil-gas_Unconventional oil and gass_reseviours.pdf
Oil-gas_Unconventional oil and gass_reseviours.pdf
M7md3li2
 
Artificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptxArtificial Intelligence (AI) basics.pptx
Artificial Intelligence (AI) basics.pptx
aditichinar
 
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptxExplainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
Explainable-Artificial-Intelligence-XAI-A-Deep-Dive (1).pptx
MahaveerVPandit
 
fluke dealers in bangalore..............
fluke dealers in bangalore..............fluke dealers in bangalore..............
fluke dealers in bangalore..............
Haresh Vaswani
 
QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)QA/QC Manager (Quality management Expert)
QA/QC Manager (Quality management Expert)
rccbatchplant
 
Reagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptxReagent dosing (Bredel) presentation.pptx
Reagent dosing (Bredel) presentation.pptx
AlejandroOdio
 
DSP and MV the Color image processing.ppt
DSP and MV the  Color image processing.pptDSP and MV the  Color image processing.ppt
DSP and MV the Color image processing.ppt
HafizAhamed8
 
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design ThinkingDT REPORT by Tech titan GROUP to introduce the subject design Thinking
DT REPORT by Tech titan GROUP to introduce the subject design Thinking
DhruvChotaliya2
 
ELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdfELectronics Boards & Product Testing_Shiju.pdf
ELectronics Boards & Product Testing_Shiju.pdf
Shiju Jacob
 
Compiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptxCompiler Design Unit1 PPT Phases of Compiler.pptx
Compiler Design Unit1 PPT Phases of Compiler.pptx
RushaliDeshmukh2
 
new ppt artificial intelligence historyyy
new ppt artificial intelligence historyyynew ppt artificial intelligence historyyy
new ppt artificial intelligence historyyy
PianoPianist
 
Data Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptxData Structures_Introduction to algorithms.pptx
Data Structures_Introduction to algorithms.pptx
RushaliDeshmukh2
 
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
211421893-M-Tech-CIVIL-Structural-Engineering-pdf.pdf
inmishra17121973
 
Smart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptxSmart_Storage_Systems_Production_Engineering.pptx
Smart_Storage_Systems_Production_Engineering.pptx
rushikeshnavghare94
 
some basics electrical and electronics knowledge
some basics electrical and electronics knowledgesome basics electrical and electronics knowledge
some basics electrical and electronics knowledge
nguyentrungdo88
 
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITYADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ADVXAI IN MALWARE ANALYSIS FRAMEWORK: BALANCING EXPLAINABILITY WITH SECURITY
ijscai
 

Threads in Operating System | Multithreading | Interprocess Communication

  • 2. PREVIOUS SESSION • Program vs Process • Process states • Process control block • Process creation through fork() • Exec(), wait and exit() system calls • Zombie and orphan process
  • 3. AGENDA • Interprocess communication • What is a thread • Thread vs process • Multithreading and multiprocessing • Multithreading models • Challenges with multithreading
  • 4. INTERVIEW QUESTIONS • What are similarities and differences between a process and a thread? • What is IPC? Give some examples of IPC • Why process coordination is necessary in OS? • What are advantages and disadvantages of using shared memory and IPC? • What is multi-tasking, multi-programming, multithreading and multiprocessing? • What are the challenges faced in multithreading programs?
  • 5. • Difference between chrome and firefox in terms of multiprocessing and multithreading? • What is the difference between named pipe and unnamed pipe? • What are the benefits of multithreading?
  • 6. INTERPROCESS COMMUNICATION • Independent vs cooperating process • Does a process shares data with other process? • Debugging becomes tough in cooperating processes. • Why process cooperation is necessary?
  • 7. Need for process cooperation • Information sharing • Computational speedup • Modularity • Convenience • Detailed explanation: https://youtu.be/7jN8tgLqbFc
  • 8. Models/Types of interprocess communication • Shared memory • A region of shared memory is first established • Processes then share information by reading and writing to this shared space. • Threads • Message passing • A link is established between two or more processes • Messages are then shared on this link • Detailed explanation: https://youtu.be/FCPUTFmAlIg
  • 10. Shared memory vs Message Passing
  • 11. Examples • Shared memory is achieved using multithreading. • Message passing examples • Sockets • Pipes • Remote procedure calls • Pipes • Ordinary pipes • Named pipes
  • 13. PIPES • Unnamed pipe • ls | grep “hello” • cat filename | grep “hello” • Named pipe • mkfifo <file name> • Unnamed pipe can only be used to communicate between parent and child processes. • A named pipe exists on the file system. • Named pipe can be used for communication over a network. • Named pipe are bidirectional.
  • 14. WHAT IS A THREAD • A thread is a basic unit of CPU utlilization. • A thread consists of: • Thread ID • Program counter • Register sets • Stack segment memory • What does CPU needs to execute instructions? • Registers • Program counter • Process is also a unit of CPU utilization, but not a basic unit. • Detailed explanation - https://youtu.be/pYbBgA76wDg
  • 15. What a thread shares with other threads? • Code section memory • Data segment memory • Heap segment memory • Open files • Signals
  • 16. • Linux has a unique implementation of threads. To the Linux kernel, there is no concept of a thread. Linux implements all threads as standard processes. • Each thread has a unique process control block and appears to the kernel as a normal process—threads just happen to share resources, such as an address space, with other processes. • Windows – explicit support for threads (lightweight process)
  • 17. Threads implementation in Linux • Normal fork() • clone(SIGCHLD, 0); • Thread implementation • clone(CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND, 0);
  • 20. Differences continued Detailed explanation - https://youtu.be/MwDccB9tvp0
  • 21. MULTITHREADING • Multiple threads within a process • Should be supported by the hardware • Concurrency vs parallelism • Most applications are multithreaded today • Browser – rendering + fetching • Web server having multiple clients • Word processor – displaying graphics + waiting for keystroke + spell check
  • 22. Benefits of multithreading • Responsiveness – browser, word-processor • Resource sharing – threads share the memory and resources by default • Economy – creating multiple processes is very costly. • Scalability – increases the parallelism, web servers
  • 23. Challenges • Concurrency issues • Multiple threads trying to update the resource at the same time. • Leads to race condition • How i++ is actually executed?
  • 24. Initially i = 7, final value = 9 and two threads incrementing i
  • 25. Initial value = 7, final value = 8
  • 26. MULTIPROCESSING • Multiple processes within a process • Using fork() to create multiple processes • Process creation is time-consuming than creating threads. • Process address space is not shared among processes.
  • 27. CPUs, cores and hyperthreading • A core is the basic computational unit of CPU. It has registers and all other resources to execute a program. • Processes -> threads • CPU are the processor chips. • Initially, a CPU had only one core. • Today, dual-core or quad-core processors • Hyper threading – allows a single core to run multiple threads. Some hardware are duplicated.
  • 29. When to use thread vs process • Threads are faster • Crashing one thread crashes other threads too. • No security between threads – lead to race condition • A tradeoff between speed vs reliability • Chrome vs firefox – multiprocessing vs multithreading • Web servers • Word processor • Computer games
  • 30. Multiprogramming, multithreading, multiprocessing • Multiprogramming – ability of the system to run multiple programs concurrently. Time sharing OS. Can happen even on a single core. • Multitasking is similar to multiprogramming as we are able to do multiple tasks at the same time. • Multiprocessing – Using multiple cores for executing multiple programs in parallel. • Multithreading – Similar to multiprocessing but here the memory is shared between threads. Usually, very fast.
  • 31. Multithreading models • How user threads are mapped to kernel threads? • Not asked in any interviews • 1:1 mapping • N:N mapping • M:N mapping • Videos: • https://youtu.be/lYNk1cNWCfc • https://youtu.be/1Jij_qY2kp0
  • 32. NEXT SESSION: PROCESS SCHEDULING ALGORITHMS