SlideShare a Scribd company logo
ICS 313 - Fundamentals of Programming Languages 1
13. Concurrency
13.1 Introduction
Concurrency can occur at four levels:
1. Machine instruction level
2. High-level language statement level
3. Unit level
4. Program level
Because there are no language issues in instruction and program-level
concurrency, they are not addressed here
The Evolution of Multiprocessor Architectures
Late 1950s - One general-purpose processor and one or more special-
purpose processors for input and output operations
Early 1960s - Multiple complete processors, used for program-level
concurrency
Mid-1960s - Multiple partial processors, used for instruction-level
concurrency
Single-Instruction Multiple-Data (SIMD) machines. The same instruction
goes to all processors, each with different data - e.g., vector processors
Multiple-Instruction Multiple-Data (MIMD) machines - Independent processors that
can be synchronized (unit-level concurrency)
ICS 313 - Fundamentals of Programming Languages 2
13.1 Introduction (continued)
A thread of control in a program is the sequence of program points
reached as control flows through the program
Categories of Concurrency
Physical concurrency - Multiple independent processors
(multiple threads of control)
Logical concurrency - The appearance of physical concurrency is
presented by time-sharing one processor
(software can be designed as if there were multiple threads of control)
Coroutines provide only quasi-concurrency
Reasons to Study Concurrency
It involves a different way of designing software that can be very useful
- many real-world situations involve concurrency
Computers capable of physical concurrency are now widely used
13.2 Intro to Subprogram-Level Concurrency
A task is a program unit that can be in concurrent execution with other
program units
Tasks differ from ordinary subprograms in that:
A task may be implicitly started
When a program unit starts the execution of a task, it is not necessarily
suspended
When a task’s execution is completed, control may not return to the caller
Tasks usually work together
A task is disjoint if it does not communicate with or affect the execution
of any other task in the program in any way
Task communication is necessary for synchronization
Task communication can be through:
Shared nonlocal variables
Parameters
Message passing
ICS 313 - Fundamentals of Programming Languages 3
13.2 Intro to Subprogram-Level Concurrency (continued)
Kinds of synchronization
Cooperation
Task A must wait for task B to complete some specific activity before task A can continue its execution e.g., the
producer-consumer problem
Competition
When two or more tasks must use some resource that cannot be simultaneously used e.g., a shared counter
Competition is usually provided by mutually exclusive access
Providing synchronization requires a mechanism for delaying task execution
Task execution control is maintained by a program called the scheduler, which
maps task execution onto available processors
Tasks can be in one of several different execution states:
New - created but not yet started
Runnable or ready - ready to run but not currently running (no available processor)
Running
Blocked - has been running, but cannot now continue (usually waiting for some
event to occur)
Dead - no longer active in any sense
13.2 Intro to Subprogram-Level Concurrency (continued)
Liveness is a characteristic that a program unit may or may not have
In sequential code, it means the unit will eventually complete its execution
In a concurrent environment, a task can easily lose its liveness
If all tasks in a concurrent environment lose their liveness, it is called
deadlock
Design Issues for Concurrency
How is cooperation synchronization provided?
How is competition synchronization provided?
How and when do tasks begin and end execution?
Are tasks statically or dynamically created?
Methods of Providing Synchronization:
Semaphores
Monitors
Message Passing
ICS 313 - Fundamentals of Programming Languages 4
13.7 Java Threads
The concurrent units in Java are run methods
The run method is inherited and overriden in subclasses of
the predefined Thread class
The Thread Class
Includes several methods (besides run)
start, which calls run , after which control returns immediately to
start
yield, which stops execution of the thread and puts it in the task
ready queue
sleep, which stops execution of the thread and blocks it from
execution for the amount of time specified in its parameter
Early versions of Java used three more Thread methods
suspend, which stops execution of the thread until it is restarted with resume
resume, which restarts a suspended thread
stop, which kills the thread
13.7 Java Threads (continued)
Competition Synchronization with Java Threads
A method that includes the synchronized modifier disallows any
other method from running on the object while it is in execution
If only a part of a method must be run without interference, it can be
synchronized
Cooperation Synchronization with Java Threads
The wait and notify methods are defined in Object, which is the root
class in Java, so all objects inherit them
The wait method must be called in a loop
Example - the queue
See Queue class (pp. 549-550) and the Producer and Consumer
classes (p. 550)

More Related Content

What's hot

Operations on Processes
Operations on ProcessesOperations on Processes
Operations on Processes
Navid Daneshvaran
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010
Nicholas Zakas
 
I2c drivers
I2c driversI2c drivers
I2c drivers
pradeep_tewani
 
Raid and its levels
Raid and its levelsRaid and its levels
Raid and its levels
IGZ Software house
 
DDR SDRAMs
DDR SDRAMsDDR SDRAMs
DDR SDRAMs
Prankit Mishra
 
Pcie drivers basics
Pcie drivers basicsPcie drivers basics
Pcie drivers basics
Venkatesh Malla
 
SNAPDRAGON SoC Family and ARM Architecture
SNAPDRAGON SoC Family and ARM Architecture SNAPDRAGON SoC Family and ARM Architecture
SNAPDRAGON SoC Family and ARM Architecture
Abdullaziz Tagawy
 
Physical Memory Models.pdf
Physical Memory Models.pdfPhysical Memory Models.pdf
Physical Memory Models.pdf
Adrian Huang
 
memory allocation methods
memory allocation methodsmemory allocation methods
memory allocation methods
Anshul gour
 
Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.
MITS Gwalior
 
Distance Vector Routing Protocols
Distance Vector Routing ProtocolsDistance Vector Routing Protocols
Distance Vector Routing Protocols
KABILESH RAMAR
 
Cache memory
Cache memoryCache memory
Cache memory
Shailesh Tanwar
 
Pcie basic
Pcie basicPcie basic
Pcie basic
Saifuddin Kaijar
 
Parallel processing
Parallel processingParallel processing
Parallel processing
rajshreemuthiah
 
Intel core i7
Intel core i7Intel core i7
Intel core i7
Amit Kundu
 
Using Terraform to manage the configuration of a Cisco ACI fabric.
Using Terraform to manage the configuration of a Cisco ACI fabric.Using Terraform to manage the configuration of a Cisco ACI fabric.
Using Terraform to manage the configuration of a Cisco ACI fabric.
Joel W. King
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
Anil Kumar Pugalia
 
AMBA Ahb 2.0
AMBA Ahb 2.0AMBA Ahb 2.0
AMBA Ahb 2.0
Akhil Srivastava
 

What's hot (20)

Operations on Processes
Operations on ProcessesOperations on Processes
Operations on Processes
 
High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010High Performance JavaScript - WebDirections USA 2010
High Performance JavaScript - WebDirections USA 2010
 
SATA Protocol
SATA ProtocolSATA Protocol
SATA Protocol
 
I2c drivers
I2c driversI2c drivers
I2c drivers
 
Raid and its levels
Raid and its levelsRaid and its levels
Raid and its levels
 
DDR SDRAMs
DDR SDRAMsDDR SDRAMs
DDR SDRAMs
 
Pcie drivers basics
Pcie drivers basicsPcie drivers basics
Pcie drivers basics
 
SNAPDRAGON SoC Family and ARM Architecture
SNAPDRAGON SoC Family and ARM Architecture SNAPDRAGON SoC Family and ARM Architecture
SNAPDRAGON SoC Family and ARM Architecture
 
Physical Memory Models.pdf
Physical Memory Models.pdfPhysical Memory Models.pdf
Physical Memory Models.pdf
 
memory allocation methods
memory allocation methodsmemory allocation methods
memory allocation methods
 
Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.Parallel programming model, language and compiler in ACA.
Parallel programming model, language and compiler in ACA.
 
Distance Vector Routing Protocols
Distance Vector Routing ProtocolsDistance Vector Routing Protocols
Distance Vector Routing Protocols
 
Cache memory
Cache memoryCache memory
Cache memory
 
Pcie basic
Pcie basicPcie basic
Pcie basic
 
Parallel processing
Parallel processingParallel processing
Parallel processing
 
Intel core i7
Intel core i7Intel core i7
Intel core i7
 
PCIe
PCIePCIe
PCIe
 
Using Terraform to manage the configuration of a Cisco ACI fabric.
Using Terraform to manage the configuration of a Cisco ACI fabric.Using Terraform to manage the configuration of a Cisco ACI fabric.
Using Terraform to manage the configuration of a Cisco ACI fabric.
 
USB Drivers
USB DriversUSB Drivers
USB Drivers
 
AMBA Ahb 2.0
AMBA Ahb 2.0AMBA Ahb 2.0
AMBA Ahb 2.0
 

Similar to 13 concurrency

CH-1SYSTEM PROGARMMING (1).pdf programing
CH-1SYSTEM PROGARMMING (1).pdf programingCH-1SYSTEM PROGARMMING (1).pdf programing
CH-1SYSTEM PROGARMMING (1).pdf programing
hundarat596
 
operating system for computer engineering ch3.ppt
operating system for computer engineering ch3.pptoperating system for computer engineering ch3.ppt
operating system for computer engineering ch3.ppt
gezaegebre1
 
ch13 here is the ppt of this chapter included pictures
ch13 here is the ppt of this chapter included picturesch13 here is the ppt of this chapter included pictures
ch13 here is the ppt of this chapter included pictures
PranjalRana4
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
Kathirvel Ayyaswamy
 
Chat application through client server management system project.pdf
Chat application through client server management system project.pdfChat application through client server management system project.pdf
Chat application through client server management system project.pdf
Kamal Acharya
 
Process Management Operating Systems .pptx
Process Management        Operating Systems .pptxProcess Management        Operating Systems .pptx
Process Management Operating Systems .pptx
SAIKRISHNADURVASULA2
 
Concurrency in c#
Concurrency in c#Concurrency in c#
Concurrency in c#
RezaHamidpour
 
Interactive debugging system
Interactive debugging systemInteractive debugging system
Interactive debugging system
Florence priyadarshini
 
Chapter 3 chapter reading task
Chapter 3 chapter reading taskChapter 3 chapter reading task
Chapter 3 chapter reading task
Grievous Humorist-Ilham
 
Spr ch-01
Spr ch-01Spr ch-01
Spr ch-01
Vasim Pathan
 
distributed-systemsfghjjjijoijioj-chap3.pptx
distributed-systemsfghjjjijoijioj-chap3.pptxdistributed-systemsfghjjjijoijioj-chap3.pptx
distributed-systemsfghjjjijoijioj-chap3.pptx
lencho3d
 
parallel programming models
 parallel programming models parallel programming models
parallel programming models
Swetha S
 
UNIT 2 ECSE-2.pptx
UNIT 2 ECSE-2.pptxUNIT 2 ECSE-2.pptx
UNIT 2 ECSE-2.pptx
AdharshKokkula
 
Mulitthread
MulitthreadMulitthread
Mulitthread
DeepaR42
 
Multi t hreading_14_10
Multi t hreading_14_10Multi t hreading_14_10
Multi t hreading_14_10
Minal Maniar
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving TechniquesAshesh R
 
Task communication
Task communicationTask communication
Task communication
1jayanti
 

Similar to 13 concurrency (20)

Java multi thread programming on cmp system
Java multi thread programming on cmp systemJava multi thread programming on cmp system
Java multi thread programming on cmp system
 
Chapter05 new
Chapter05 newChapter05 new
Chapter05 new
 
CH-1SYSTEM PROGARMMING (1).pdf programing
CH-1SYSTEM PROGARMMING (1).pdf programingCH-1SYSTEM PROGARMMING (1).pdf programing
CH-1SYSTEM PROGARMMING (1).pdf programing
 
operating system for computer engineering ch3.ppt
operating system for computer engineering ch3.pptoperating system for computer engineering ch3.ppt
operating system for computer engineering ch3.ppt
 
ch13 here is the ppt of this chapter included pictures
ch13 here is the ppt of this chapter included picturesch13 here is the ppt of this chapter included pictures
ch13 here is the ppt of this chapter included pictures
 
CS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMSCS9222 ADVANCED OPERATING SYSTEMS
CS9222 ADVANCED OPERATING SYSTEMS
 
Chat application through client server management system project.pdf
Chat application through client server management system project.pdfChat application through client server management system project.pdf
Chat application through client server management system project.pdf
 
Process Management Operating Systems .pptx
Process Management        Operating Systems .pptxProcess Management        Operating Systems .pptx
Process Management Operating Systems .pptx
 
Concurrency in c#
Concurrency in c#Concurrency in c#
Concurrency in c#
 
Interactive debugging system
Interactive debugging systemInteractive debugging system
Interactive debugging system
 
Chapter 3 chapter reading task
Chapter 3 chapter reading taskChapter 3 chapter reading task
Chapter 3 chapter reading task
 
Threads
ThreadsThreads
Threads
 
Spr ch-01
Spr ch-01Spr ch-01
Spr ch-01
 
distributed-systemsfghjjjijoijioj-chap3.pptx
distributed-systemsfghjjjijoijioj-chap3.pptxdistributed-systemsfghjjjijoijioj-chap3.pptx
distributed-systemsfghjjjijoijioj-chap3.pptx
 
parallel programming models
 parallel programming models parallel programming models
parallel programming models
 
UNIT 2 ECSE-2.pptx
UNIT 2 ECSE-2.pptxUNIT 2 ECSE-2.pptx
UNIT 2 ECSE-2.pptx
 
Mulitthread
MulitthreadMulitthread
Mulitthread
 
Multi t hreading_14_10
Multi t hreading_14_10Multi t hreading_14_10
Multi t hreading_14_10
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Task communication
Task communicationTask communication
Task communication
 

More from jigeno

Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1
jigeno
 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
jigeno
 
16 logical programming
16 logical programming16 logical programming
16 logical programmingjigeno
 
15 functional programming
15 functional programming15 functional programming
15 functional programmingjigeno
 
15 functional programming
15 functional programming15 functional programming
15 functional programmingjigeno
 
14 exception handling
14 exception handling14 exception handling
14 exception handlingjigeno
 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programmingjigeno
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data typesjigeno
 
9 subprograms
9 subprograms9 subprograms
9 subprogramsjigeno
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structurejigeno
 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statementsjigeno
 
6 data types
6 data types6 data types
6 data typesjigeno
 
5 names
5 names5 names
5 namesjigeno
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysisjigeno
 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semanticsjigeno
 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languagesjigeno
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminariesjigeno
 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2jigeno
 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1jigeno
 

More from jigeno (20)

Access2007 part1
Access2007 part1Access2007 part1
Access2007 part1
 
Basic introduction to ms access
Basic introduction to ms accessBasic introduction to ms access
Basic introduction to ms access
 
Bsit1
Bsit1Bsit1
Bsit1
 
16 logical programming
16 logical programming16 logical programming
16 logical programming
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
15 functional programming
15 functional programming15 functional programming
15 functional programming
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
 
12 object oriented programming
12 object oriented programming12 object oriented programming
12 object oriented programming
 
11 abstract data types
11 abstract data types11 abstract data types
11 abstract data types
 
9 subprograms
9 subprograms9 subprograms
9 subprograms
 
8 statement-level control structure
8 statement-level control structure8 statement-level control structure
8 statement-level control structure
 
7 expressions and assignment statements
7 expressions and assignment statements7 expressions and assignment statements
7 expressions and assignment statements
 
6 data types
6 data types6 data types
6 data types
 
5 names
5 names5 names
5 names
 
4 lexical and syntax analysis
4 lexical and syntax analysis4 lexical and syntax analysis
4 lexical and syntax analysis
 
3 describing syntax and semantics
3 describing syntax and semantics3 describing syntax and semantics
3 describing syntax and semantics
 
2 evolution of the major programming languages
2 evolution of the major programming languages2 evolution of the major programming languages
2 evolution of the major programming languages
 
1 preliminaries
1 preliminaries1 preliminaries
1 preliminaries
 
Access2007 m2
Access2007 m2Access2007 m2
Access2007 m2
 
Access2007 m1
Access2007 m1Access2007 m1
Access2007 m1
 

Recently uploaded

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 

Recently uploaded (20)

Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 

13 concurrency

  • 1. ICS 313 - Fundamentals of Programming Languages 1 13. Concurrency 13.1 Introduction Concurrency can occur at four levels: 1. Machine instruction level 2. High-level language statement level 3. Unit level 4. Program level Because there are no language issues in instruction and program-level concurrency, they are not addressed here The Evolution of Multiprocessor Architectures Late 1950s - One general-purpose processor and one or more special- purpose processors for input and output operations Early 1960s - Multiple complete processors, used for program-level concurrency Mid-1960s - Multiple partial processors, used for instruction-level concurrency Single-Instruction Multiple-Data (SIMD) machines. The same instruction goes to all processors, each with different data - e.g., vector processors Multiple-Instruction Multiple-Data (MIMD) machines - Independent processors that can be synchronized (unit-level concurrency)
  • 2. ICS 313 - Fundamentals of Programming Languages 2 13.1 Introduction (continued) A thread of control in a program is the sequence of program points reached as control flows through the program Categories of Concurrency Physical concurrency - Multiple independent processors (multiple threads of control) Logical concurrency - The appearance of physical concurrency is presented by time-sharing one processor (software can be designed as if there were multiple threads of control) Coroutines provide only quasi-concurrency Reasons to Study Concurrency It involves a different way of designing software that can be very useful - many real-world situations involve concurrency Computers capable of physical concurrency are now widely used 13.2 Intro to Subprogram-Level Concurrency A task is a program unit that can be in concurrent execution with other program units Tasks differ from ordinary subprograms in that: A task may be implicitly started When a program unit starts the execution of a task, it is not necessarily suspended When a task’s execution is completed, control may not return to the caller Tasks usually work together A task is disjoint if it does not communicate with or affect the execution of any other task in the program in any way Task communication is necessary for synchronization Task communication can be through: Shared nonlocal variables Parameters Message passing
  • 3. ICS 313 - Fundamentals of Programming Languages 3 13.2 Intro to Subprogram-Level Concurrency (continued) Kinds of synchronization Cooperation Task A must wait for task B to complete some specific activity before task A can continue its execution e.g., the producer-consumer problem Competition When two or more tasks must use some resource that cannot be simultaneously used e.g., a shared counter Competition is usually provided by mutually exclusive access Providing synchronization requires a mechanism for delaying task execution Task execution control is maintained by a program called the scheduler, which maps task execution onto available processors Tasks can be in one of several different execution states: New - created but not yet started Runnable or ready - ready to run but not currently running (no available processor) Running Blocked - has been running, but cannot now continue (usually waiting for some event to occur) Dead - no longer active in any sense 13.2 Intro to Subprogram-Level Concurrency (continued) Liveness is a characteristic that a program unit may or may not have In sequential code, it means the unit will eventually complete its execution In a concurrent environment, a task can easily lose its liveness If all tasks in a concurrent environment lose their liveness, it is called deadlock Design Issues for Concurrency How is cooperation synchronization provided? How is competition synchronization provided? How and when do tasks begin and end execution? Are tasks statically or dynamically created? Methods of Providing Synchronization: Semaphores Monitors Message Passing
  • 4. ICS 313 - Fundamentals of Programming Languages 4 13.7 Java Threads The concurrent units in Java are run methods The run method is inherited and overriden in subclasses of the predefined Thread class The Thread Class Includes several methods (besides run) start, which calls run , after which control returns immediately to start yield, which stops execution of the thread and puts it in the task ready queue sleep, which stops execution of the thread and blocks it from execution for the amount of time specified in its parameter Early versions of Java used three more Thread methods suspend, which stops execution of the thread until it is restarted with resume resume, which restarts a suspended thread stop, which kills the thread 13.7 Java Threads (continued) Competition Synchronization with Java Threads A method that includes the synchronized modifier disallows any other method from running on the object while it is in execution If only a part of a method must be run without interference, it can be synchronized Cooperation Synchronization with Java Threads The wait and notify methods are defined in Object, which is the root class in Java, so all objects inherit them The wait method must be called in a loop Example - the queue See Queue class (pp. 549-550) and the Producer and Consumer classes (p. 550)