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