Information Technology Reference
In-Depth Information
much more likely that you will write code that is not only correct but also easy
for others to read, understand, and maintain.
Of course, writing individual shared objects is not enough. Most programs
have multiple shared objects, and new issues arise when combining them. But,
before trying to compose multiple shared objects, we must make sure that each
individual object works. Chapter ?? discusses the issues that arise when pro-
grams use multiple shared objects.
5.6.1
High level design
In the discussion above, observe that a shared object has public methods, private
methods, state variables, and synchronization variables, where a shared object's
synchronization variables are a lock and one or more condition variables. At this
level, shared object programming is basically like standard object oriented pro-
gramming, except we've added synchronization variables to each shared object.
This similarity is deliberate: synchronization variables are carefully defined so
that we can continue to apply familiar techniques for programming and reason-
ing about objects.
So, most of high level design challenges for a shared object's class are the
same as for class design in single-threaded programming:
Decompose the problem into objects
For each object
{ Dene a clean interface
{ Identify the right internal state and invariants to support that inter-
face
{ Implement methods with appropriate algorithms to manipulate that
state.
All of these steps require creativity and good engineering judgement and in-
tuition. Going from single-threaded to multi-threaded programming does not
make these these steps particularly more dicult.
Compared to what you do to implement a class in a single-threaded pro-
gram, the new steps needed for the multi-threaded case for shared objects are
straightforward.
Add a lock
Add code to acquire and release the lock
Identify and add condition variables
Search WWH ::




Custom Search