SlideShare a Scribd company logo
1 of 50
CONCURRENT PROGRAMING
AND COMPONENTS
CHAPTER GOALS
 Understand why concurrent programming is
important.
 Give a working definition of concurrent program.
 Understand the two types of synchronization and
give examples of each.
CHAPTER GOALS
 Give a definition of the term component and
know what special problems can be encountered
when using components.
 Describe several different reasons for doing
concurrent programming and how each of these
reasons leads to different design decisions and
different program implementation.
WHAT IS CONCURRENT PROGRAMMING ?
 The purpose of this course is to help the
students understand how to create
concurrent programs with special concurrent
object, called concurrent components.
 This components are used only in
concurrent programs.
WHAT IS CONCURRENT PROGRAMMING ?
 A good definition of a concurrent program is needed
before components can be defined and methods given
for their implementation.
 This chapter provides a good working definition of a
concurrent program after explaining why concurrent
programming is important concept for programmer to
know.
WHAT IS CONCURRENT PROGRAMMING ?
 The working definition of a concurrent
program provided here will serve as a basis
for understand concurrent programming
throughout the course.
WHAT IS CONCURRENT PROGRAMMING ?
 The definition of an asynchronous activity
leads to very simple definition of
concurrency:
Concurrency is defined as the presence of
two or more asynchronous activities.
ASYNCHRONOUS ACTIVITIES
 Defining a concurrent program begins by
defining the basic building block of a
program which will be called an Activities.
ASYNCHRONOUS ACTIVITIES
 An activities could be formally defined as
anything that could be done by abstract
Turing machine or as an algorithm.
ASYNCHRONOUS ACTIVITIES
 Like a working definition , it is sufficient to
define an activity as simply a series of steps
implemented to perform a task.
 Baking a pie or calculating a Fibonacci
number on a computer.
ASYNCHRONOUS ACTIVITIES
 The steps required to perform a task will be
called an ordering.
ASYNCHRONOUS ACTIVITIES
 Activities can be broken down into
subactivities, each an activity itself.
 Baking a pie could consist of making the
crust, making the filling,filling the crust with
the filling, and baking the pie.
Make Crust Make Filling Add Filling Bake a Pie
ASYNCHRONOUS ACTIVITIES
 If the order of these activities is completely fixed,
then the ordering is called a total ordering, as
all steps in all activities are ordered.
 In the case of a total orderings of events, the
next step to be taken can always be determined
by the activiity.
ASYNCHRONOUS ACTIVITIES
 An activities for which the order of the
steps is determined by activity is called a
synchronous activity.
 If the order can be changed, then the
ordering is called partial ordering.
ASYNCHRONOUS ACTIVITIES
 If one activity must always finish before the
another begins, it posible to implement this
behavior with a synchronous activity.
 A special case occurs when, for a partial
ordering, the next step is not determined by a
single activity.
ASYNCHRONOUS ACTIVITIES
t1c
t1f
Make Filling
Make a Crust
t2c
t2f
Add Filling Bake Pie
ASYNCHRONOUS ACTIVITIES
 The activity where the steps involved in
the two substaks are being executed
independently, or asynchronously, of each
other is called asynchronous activity.
ASYNCHRONOUS ACTIVITIES
 The definition of an asynchronous activity
leads to a very simple definition of
concurrency:
 Concurrency is defined as the presence of
two or more asynchronous activities.
ASYNCHRONOUS ACTIVITIES
 When asynchronous activities are present
in a program, it is possible (but not
necesary) for the steps for the two
activities to interleave.
ASYNCHRONOUS ACTIVITIES
 From the definition of asynchronous
activities the two activities do not have to
run at the same time; they simple have to
be able to run at the same time.
ASYNCHRONOUS ACTIVITIES
 The problems that will be encountered in
concurrency occur not because the
activities execute at the same time but
because they can interleave their
executions.
ASYNCHRONOUS ACTIVITIES
 If a program allows activities to
interleave, it must protect against the ill
effects of that interleaving whether it
occurs or not.
ASYNCHRONOUS ACTIVITIES
 The importance of the improvement of
this definition of concurrency over the
definition of concurrency as a multiple
activities happening at the same time
cannot be overemphasized.
ASYNCHRONOUS ACTIVITIES
 If a concurrent program does not actually
run two activities at the same time, but it
can do so, then action must be taken to
make sure problems do not occur.
ASYNCHRONOUS ACTIVITIES
 Two threads running in a program are
asynchronous activities,thus they are
concurrent.
ASYNCHRONOUS ACTIVITIES
 Two computers running in different cities
are also asynchronous activities, so the
definition of concurrent must be further
tightened.
SYNCHRONIZATION OF ASYNCHRONOUS ACTIVITIES
 That two or more asynchronous activities
are concurrent is good definition of
concurrency, but it is not useful definition.
SYNCHRONIZATION OF ASYNCHRONOUS ACTIVITIES
 Sebesta R. say that, “Synchronization is
a mechanism that controls the order in
which tasks execute”.
Concepts of Programming Languages
,Addison-Wesley, Reading MA.1999
COMPETITIVE AND COOPERATIVE SYNCHRONIZATION
 Sebesta R. , define two types of
synchronization:
SYNCHRONIZATION OF ASYNCHRONOUS ACTIVITIES
 Sebesta R. , define two types of
synchronization:
Competitives synchronization
Cooperative synchronization
COMPETITIVE AND COOPERATIVE SYNCHRONIZATION
Make Filling
Make a Crust
Cooperative
Synchronization
Add Filling Bake PieMixing
Bold
Competitive
Synchronizaation
CONCURRENT PROGRAMMING
 Concurrent Program: A program that
contains asynchronous activities which
synchronize at one or more points or on one
or more resources during execution.
COMPONENTS
 An interesting way to look at a
concurrent program is to think of it
as containing two types of units,
activities that act on other entities or
entities that control the interactions
of these activities.
COMPONENTS
 If this units are objects, then in a
concurrent program all objects in the
program can be made to be either active
(asynchronous activities such as threads)
or pasive ( such as a shared resource or
an event that is used for synchronization).
COMPONENTS
 Other types of simple, non-
concurrennt objects are used by
active and passive objects, such as
Vector or StringTokenizers, but these
are not involved in the concurrency in
the program.
COMPONENTS
 Passive objects, which from
now on will be called
concurrent component or
simple components,are more
difficult for most students.
COMPONENTS
 This is likely because they
provide the infraestructure for
the asynchronous activities that
executed in a concurrent
program.
COMPONENTS
 Components in the example of
making a pie are the shared
mixing bowl and the event that
significates that the preparation
of the crust and filling is
completed.
COMPONENTS
 The components control the
behavior of the asynchronous
activities so that they
coordinate and produce a
correct result.
COMPONENTS
 The components sit between asynchronous
activities and are shared and used by
multiple asynchronous activities.
COMPONENTS
 Note that not all objects that are non-active
are components.
 A vector is safe to use in a multi-threaded
program, but it is not component because
even if it is used by a number of threads it is
not normally used to coordinate between
those threads.
COMPONENTS
 Objects are added or removed from vector,
but the vector is used just to store data
elements, not to coordinate the
asynchronous activities.
COMPONENTS
 A special type of vector called bounded
buffer is actually used to coordinate
between asynchronous activities.
COMPONENTS
 Because components provide an
infraestructur for asynchronous activities and
coordinate between these activities, they
have a number of characteristics that must
be considered that do not exist when
implementing normal object.
SOME CHARACTERISTICS OF COMPONENTS
 Because components coordinate between
several threads, they can not be created or
owned by a single thread; therefore, some
mechanism must be used to allow these
objects to be registered, or to register
themselves, with other objects representing
the asynchronous activities.
SOME CHARACTERISTICS OF COMPONENTS
 Because components are used in separate
asynchronous activities and, in the extreme
case of distributing computing, on physically
different computers, some mechanism must
be implemented to allows the components
to communicate with asynchronous activities.
SOME CHARACTERISTICS OF COMPONENTS
 Unlike objects for asynchronous activities,
which can be designed using procedural
flow, the logic in a component is generally
organized around the state of the
component when it is executed. Some
mechanism needs to be designed to
effectively implement the components to
allow them to provide this coordination.
SOME CHARACTERISTICS OF COMPONENTS
 Some harmfull interactions, called race
conditions, can occur if the object are not
properly designed. One way to avoid race
conditions is to make all the methods in the
object synchronized and not allow an object
to give up the object’s lock while executing.
SOME CHARACTERISTICS OF COMPONENTS
This is called complete synchronization
and is sufficient for non component
objects such as String or a Vector;
however, components must coordinate
between several objects, and complete
synchronization is too restrictive to
effectively implement this coordination.
SOME CHARACTERISTICS OF COMPONENTS
 A second type of harmful interaction, called a
deadlock, can result if the component is not
properly designed. Deadlock can occur in
any concurrent program when objects are
improperly handled; however, the posibility
of deadlock can actually be built into
components that are not designed properly,
even if the component is used correctly.

More Related Content

Similar to Concurrent programing

Open modeling and simulation framework for evolutive analysis
Open modeling and simulation framework for evolutive analysisOpen modeling and simulation framework for evolutive analysis
Open modeling and simulation framework for evolutive analysis
Servicio de Difusión de la Creación Intelectual (SEDICI)
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
MugiiiReee
 
Component based models and technology
Component based models and technologyComponent based models and technology
Component based models and technology
Saransh Garg
 
07 software design
07   software design07   software design
07 software design
kebsterz
 
07 software design
07   software design07   software design
07 software design
kebsterz
 

Similar to Concurrent programing (20)

Fundamentals of Software Engineering
Fundamentals of Software Engineering Fundamentals of Software Engineering
Fundamentals of Software Engineering
 
Async.pdf
Async.pdfAsync.pdf
Async.pdf
 
Synchronous vs Asynchronous Programming
Synchronous vs Asynchronous ProgrammingSynchronous vs Asynchronous Programming
Synchronous vs Asynchronous Programming
 
Multi projects
Multi projectsMulti projects
Multi projects
 
Open modeling and simulation framework for evolutive analysis
Open modeling and simulation framework for evolutive analysisOpen modeling and simulation framework for evolutive analysis
Open modeling and simulation framework for evolutive analysis
 
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx11.11.2020 - Unit 5-3  ACTIVITY, MENU AND SQLITE DATABASE.pptx
11.11.2020 - Unit 5-3 ACTIVITY, MENU AND SQLITE DATABASE.pptx
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
Solid Principles I: The Secret of Life
Solid Principles I: The Secret of LifeSolid Principles I: The Secret of Life
Solid Principles I: The Secret of Life
 
Activities vs fragment
Activities vs fragmentActivities vs fragment
Activities vs fragment
 
Lab3-Android
Lab3-AndroidLab3-Android
Lab3-Android
 
A Recent Encounter
A Recent EncounterA Recent Encounter
A Recent Encounter
 
Component based models and technology
Component based models and technologyComponent based models and technology
Component based models and technology
 
Overview Sphere M&E system
Overview Sphere M&E systemOverview Sphere M&E system
Overview Sphere M&E system
 
Uml examples
Uml examplesUml examples
Uml examples
 
Content-Driven Apps with React
Content-Driven Apps with ReactContent-Driven Apps with React
Content-Driven Apps with React
 
Lec2.pptx
Lec2.pptxLec2.pptx
Lec2.pptx
 
Component based models and technology
Component based models and technologyComponent based models and technology
Component based models and technology
 
07 software design
07   software design07   software design
07 software design
 
07 software design
07   software design07   software design
07 software design
 
GUI Programming in JAVA (Using Netbeans) - A Review
GUI Programming in JAVA (Using Netbeans) -  A ReviewGUI Programming in JAVA (Using Netbeans) -  A Review
GUI Programming in JAVA (Using Netbeans) - A Review
 

More from Alvaro Pino (10)

Module 01a2020
Module 01a2020Module 01a2020
Module 01a2020
 
Module 01a2020
Module 01a2020Module 01a2020
Module 01a2020
 
Regla derecha izquierda
Regla derecha   izquierdaRegla derecha   izquierda
Regla derecha izquierda
 
Chap 15gpin
Chap 15gpinChap 15gpin
Chap 15gpin
 
Chap 15fpin
Chap 15fpinChap 15fpin
Chap 15fpin
 
Chap 15epin
Chap 15epinChap 15epin
Chap 15epin
 
Chap 15dpin
Chap 15dpinChap 15dpin
Chap 15dpin
 
Chap 15cpin
Chap 15cpinChap 15cpin
Chap 15cpin
 
Chap 15bpin
Chap 15bpinChap 15bpin
Chap 15bpin
 
Chap 15apin
Chap 15apinChap 15apin
Chap 15apin
 

Recently uploaded

Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
Elizabeth Walsh
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MysoreMuleSoftMeetup
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
EADTU
 

Recently uploaded (20)

Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptxMichaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
Michaelis Menten Equation and Estimation Of Vmax and Tmax.pptx
 
Orientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdfOrientation Canvas Course Presentation.pdf
Orientation Canvas Course Presentation.pdf
 
Observing-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptxObserving-Correct-Grammar-in-Making-Definitions.pptx
Observing-Correct-Grammar-in-Making-Definitions.pptx
 
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
MuleSoft Integration with AWS Textract | Calling AWS Textract API |AWS - Clou...
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
VAMOS CUIDAR DO NOSSO PLANETA! .
VAMOS CUIDAR DO NOSSO PLANETA!                    .VAMOS CUIDAR DO NOSSO PLANETA!                    .
VAMOS CUIDAR DO NOSSO PLANETA! .
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 
PANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptxPANDITA RAMABAI- Indian political thought GENDER.pptx
PANDITA RAMABAI- Indian political thought GENDER.pptx
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17Model Attribute _rec_name in the Odoo 17
Model Attribute _rec_name in the Odoo 17
 
Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...Andreas Schleicher presents at the launch of What does child empowerment mean...
Andreas Schleicher presents at the launch of What does child empowerment mean...
 
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes GuàrdiaPersonalisation of Education by AI and Big Data - Lourdes Guàrdia
Personalisation of Education by AI and Big Data - Lourdes Guàrdia
 

Concurrent programing

  • 2. CHAPTER GOALS  Understand why concurrent programming is important.  Give a working definition of concurrent program.  Understand the two types of synchronization and give examples of each.
  • 3. CHAPTER GOALS  Give a definition of the term component and know what special problems can be encountered when using components.  Describe several different reasons for doing concurrent programming and how each of these reasons leads to different design decisions and different program implementation.
  • 4. WHAT IS CONCURRENT PROGRAMMING ?  The purpose of this course is to help the students understand how to create concurrent programs with special concurrent object, called concurrent components.  This components are used only in concurrent programs.
  • 5. WHAT IS CONCURRENT PROGRAMMING ?  A good definition of a concurrent program is needed before components can be defined and methods given for their implementation.  This chapter provides a good working definition of a concurrent program after explaining why concurrent programming is important concept for programmer to know.
  • 6. WHAT IS CONCURRENT PROGRAMMING ?  The working definition of a concurrent program provided here will serve as a basis for understand concurrent programming throughout the course.
  • 7. WHAT IS CONCURRENT PROGRAMMING ?  The definition of an asynchronous activity leads to very simple definition of concurrency: Concurrency is defined as the presence of two or more asynchronous activities.
  • 8. ASYNCHRONOUS ACTIVITIES  Defining a concurrent program begins by defining the basic building block of a program which will be called an Activities.
  • 9. ASYNCHRONOUS ACTIVITIES  An activities could be formally defined as anything that could be done by abstract Turing machine or as an algorithm.
  • 10. ASYNCHRONOUS ACTIVITIES  Like a working definition , it is sufficient to define an activity as simply a series of steps implemented to perform a task.  Baking a pie or calculating a Fibonacci number on a computer.
  • 11. ASYNCHRONOUS ACTIVITIES  The steps required to perform a task will be called an ordering.
  • 12. ASYNCHRONOUS ACTIVITIES  Activities can be broken down into subactivities, each an activity itself.  Baking a pie could consist of making the crust, making the filling,filling the crust with the filling, and baking the pie. Make Crust Make Filling Add Filling Bake a Pie
  • 13. ASYNCHRONOUS ACTIVITIES  If the order of these activities is completely fixed, then the ordering is called a total ordering, as all steps in all activities are ordered.  In the case of a total orderings of events, the next step to be taken can always be determined by the activiity.
  • 14. ASYNCHRONOUS ACTIVITIES  An activities for which the order of the steps is determined by activity is called a synchronous activity.  If the order can be changed, then the ordering is called partial ordering.
  • 15. ASYNCHRONOUS ACTIVITIES  If one activity must always finish before the another begins, it posible to implement this behavior with a synchronous activity.  A special case occurs when, for a partial ordering, the next step is not determined by a single activity.
  • 16. ASYNCHRONOUS ACTIVITIES t1c t1f Make Filling Make a Crust t2c t2f Add Filling Bake Pie
  • 17. ASYNCHRONOUS ACTIVITIES  The activity where the steps involved in the two substaks are being executed independently, or asynchronously, of each other is called asynchronous activity.
  • 18. ASYNCHRONOUS ACTIVITIES  The definition of an asynchronous activity leads to a very simple definition of concurrency:  Concurrency is defined as the presence of two or more asynchronous activities.
  • 19. ASYNCHRONOUS ACTIVITIES  When asynchronous activities are present in a program, it is possible (but not necesary) for the steps for the two activities to interleave.
  • 20. ASYNCHRONOUS ACTIVITIES  From the definition of asynchronous activities the two activities do not have to run at the same time; they simple have to be able to run at the same time.
  • 21. ASYNCHRONOUS ACTIVITIES  The problems that will be encountered in concurrency occur not because the activities execute at the same time but because they can interleave their executions.
  • 22. ASYNCHRONOUS ACTIVITIES  If a program allows activities to interleave, it must protect against the ill effects of that interleaving whether it occurs or not.
  • 23. ASYNCHRONOUS ACTIVITIES  The importance of the improvement of this definition of concurrency over the definition of concurrency as a multiple activities happening at the same time cannot be overemphasized.
  • 24. ASYNCHRONOUS ACTIVITIES  If a concurrent program does not actually run two activities at the same time, but it can do so, then action must be taken to make sure problems do not occur.
  • 25. ASYNCHRONOUS ACTIVITIES  Two threads running in a program are asynchronous activities,thus they are concurrent.
  • 26. ASYNCHRONOUS ACTIVITIES  Two computers running in different cities are also asynchronous activities, so the definition of concurrent must be further tightened.
  • 27. SYNCHRONIZATION OF ASYNCHRONOUS ACTIVITIES  That two or more asynchronous activities are concurrent is good definition of concurrency, but it is not useful definition.
  • 28. SYNCHRONIZATION OF ASYNCHRONOUS ACTIVITIES  Sebesta R. say that, “Synchronization is a mechanism that controls the order in which tasks execute”. Concepts of Programming Languages ,Addison-Wesley, Reading MA.1999
  • 29. COMPETITIVE AND COOPERATIVE SYNCHRONIZATION  Sebesta R. , define two types of synchronization:
  • 30. SYNCHRONIZATION OF ASYNCHRONOUS ACTIVITIES  Sebesta R. , define two types of synchronization: Competitives synchronization Cooperative synchronization
  • 31. COMPETITIVE AND COOPERATIVE SYNCHRONIZATION Make Filling Make a Crust Cooperative Synchronization Add Filling Bake PieMixing Bold Competitive Synchronizaation
  • 32. CONCURRENT PROGRAMMING  Concurrent Program: A program that contains asynchronous activities which synchronize at one or more points or on one or more resources during execution.
  • 33. COMPONENTS  An interesting way to look at a concurrent program is to think of it as containing two types of units, activities that act on other entities or entities that control the interactions of these activities.
  • 34. COMPONENTS  If this units are objects, then in a concurrent program all objects in the program can be made to be either active (asynchronous activities such as threads) or pasive ( such as a shared resource or an event that is used for synchronization).
  • 35. COMPONENTS  Other types of simple, non- concurrennt objects are used by active and passive objects, such as Vector or StringTokenizers, but these are not involved in the concurrency in the program.
  • 36. COMPONENTS  Passive objects, which from now on will be called concurrent component or simple components,are more difficult for most students.
  • 37. COMPONENTS  This is likely because they provide the infraestructure for the asynchronous activities that executed in a concurrent program.
  • 38. COMPONENTS  Components in the example of making a pie are the shared mixing bowl and the event that significates that the preparation of the crust and filling is completed.
  • 39. COMPONENTS  The components control the behavior of the asynchronous activities so that they coordinate and produce a correct result.
  • 40. COMPONENTS  The components sit between asynchronous activities and are shared and used by multiple asynchronous activities.
  • 41. COMPONENTS  Note that not all objects that are non-active are components.  A vector is safe to use in a multi-threaded program, but it is not component because even if it is used by a number of threads it is not normally used to coordinate between those threads.
  • 42. COMPONENTS  Objects are added or removed from vector, but the vector is used just to store data elements, not to coordinate the asynchronous activities.
  • 43. COMPONENTS  A special type of vector called bounded buffer is actually used to coordinate between asynchronous activities.
  • 44. COMPONENTS  Because components provide an infraestructur for asynchronous activities and coordinate between these activities, they have a number of characteristics that must be considered that do not exist when implementing normal object.
  • 45. SOME CHARACTERISTICS OF COMPONENTS  Because components coordinate between several threads, they can not be created or owned by a single thread; therefore, some mechanism must be used to allow these objects to be registered, or to register themselves, with other objects representing the asynchronous activities.
  • 46. SOME CHARACTERISTICS OF COMPONENTS  Because components are used in separate asynchronous activities and, in the extreme case of distributing computing, on physically different computers, some mechanism must be implemented to allows the components to communicate with asynchronous activities.
  • 47. SOME CHARACTERISTICS OF COMPONENTS  Unlike objects for asynchronous activities, which can be designed using procedural flow, the logic in a component is generally organized around the state of the component when it is executed. Some mechanism needs to be designed to effectively implement the components to allow them to provide this coordination.
  • 48. SOME CHARACTERISTICS OF COMPONENTS  Some harmfull interactions, called race conditions, can occur if the object are not properly designed. One way to avoid race conditions is to make all the methods in the object synchronized and not allow an object to give up the object’s lock while executing.
  • 49. SOME CHARACTERISTICS OF COMPONENTS This is called complete synchronization and is sufficient for non component objects such as String or a Vector; however, components must coordinate between several objects, and complete synchronization is too restrictive to effectively implement this coordination.
  • 50. SOME CHARACTERISTICS OF COMPONENTS  A second type of harmful interaction, called a deadlock, can result if the component is not properly designed. Deadlock can occur in any concurrent program when objects are improperly handled; however, the posibility of deadlock can actually be built into components that are not designed properly, even if the component is used correctly.