Creating a Synchronized Data Output Stream
The first example demonstrates how to create and use a thread-safe chain of streaming elements. It creates a synchronized data output stream (RWSynchronizedDataOutputStreamImp) that connects to a RWNativeDataToByteOutputStreamImp stream, which encodes C++ base types as a sequence of bytes using their native binary representation.
The RWNativeDataToByteOutputStreamImp stream is in turn connected to a buffered binary output stream that sends the transformed bytes to a file. The class RWBufferedByteOutputStreamImp is connected to class RWByteToStreambufOutputStreamImp to provide the buffered byte output stream. This example requires the Streams package, as well as the Execution Tracing, Thread-compatible Exception, Synchronization, Smart Pointer, Threading, Functor, and Interthread Communication packages from the Threads Module.
Figure 15 is a representation of the chain of streaming elements used in this example.
Figure 15 – Thread-safe chain of streaming elements
The complete source for the examples in Creating and Managing Threads Using Active Objects and Creating and Sharing a Synchronized Data Output Stream Among Several Active Objects is located in examples\stream\dataFilteredWrite.cpp. Only part of the code is presented here.