| ||||||
|
|
This version of tcdemo is written in C++ and uses POSIX Threads for multi tasking. Source CodeYou may download the source from here. The files are:
BackgroundWe wrote tcdemo2 using the GNU C++ programming language, and using an evaluation copy of a C++ OOP tool from Object Software International. (Note: We do not endorse Object Software International or their products, but for the purposes of the demonstration we thought it would be interesting to use a commercial tool to assist with the programming.) The C++ version was written from scratch, and makes use of object oriented program techniques where possible. Using the earlier ANSI C version as a guide, we wrote a C++ version, taking care to identify classes and instances of classes, and to associate these with files. Each object class is defined in a header file with a filename that is similar to the name of the class. And each class implementation is located in a single ".cpp" file. Then after the C++ version was tested and shown to generate the same output as the ANSI C version, we reverse-engineered the C++ source into an OMT object model. Then after some refinement of the model, we arrived at a new set of sources. The model (in OMT format) is shown in Figure 1.
One particularly interesting feature of the demonstration is way we have created active objects. Such objects include a POSIX thread, and the thread executes the body code of the object. Other code, such as public operations is run by other threads, and is synchronized with the body code by means of a mutex and a number of condition variables. The base class for all active objects is the class CThread. Classes derived from CThread are also active, and the body code is supplied by overriding the virtual function 'Body'. |
|