NAME
stream_MT - base class to provide dynamic changing of ios-
tream class objects to and from MT safety.
SYNOPSIS
#include <rlocks.h>
typedef char stream_bool_t;
class stream_MT {
public:
enum { unsafe_object=0, safe_object=1 };
stream_MT();
stream_MT(stream_bool_t);
stream_bool_t test_safe_flag();
void set_safe_flag(stream_bool_t);
friend class stream_locker;
};
DESCRIPTION
Class stream_MT is a base class that allows the iostream
classes in libC to work correctly in a multi-threaded
environment. The classes ios and streambuf are derived from
stream_MT.
The multi-thread (MT) safety of an iostream object can be
dynamically changed by setting a safe flag using the member
function: set_safe_flag(). An argument with the value of
stream_MT::safe_object sets the iostream object to be MT
safe, an argument with the value of stream_MT::unsafe_object
sets the object to be MT-unsafe. The current state of the
iostream object can be determined by the member function:
test_safe_flag(). When an iostream object is MT safe there
is a certain amount of overhead associated with internal
locking in the object. The overhead can be avoided by set-
ting the safe flag to zero which disables internal locking.
Constructors
stream_MT();
By default the safe_flag of the class object is set to
stream_MT::safe_object
stream_MT(stream_bool_t);
The default can be changed by providing an explicit
value for the safe flag.
Member functions
stream_bool_t test_safe_flag();
Returns the current value of the safe flag. A value
other than stream_MT::unsafe_object indicates the ios-
tream object is MT safe and locking is enabled.
void set_safe_flag(stream_bool_t);
Sets the internal safe flag of the iostream object to
the value given as an argument. Setting the value to
non-zero enables locking and makes the object MT safe.
Setting the value to zero does the reverse.
SEE ALSO
C++ Library Reference
Environment."
Chapter 4, "Using Classic iostream in a Multithreaded