HP aC++/HP C A.06.25 Programmer's Guide

Rogue Wave Standard C++ Library 2.2.1
For both 32-bit and 64-bit libraries:
libstd_v2.so and libstd_v2.a
libCsup.so and libCsup.a
Rogue Wave Standard C++ Library 1.2.1 and Tools.h++ 7.0.6
For both 32-bit and 64-bit libraries:
libstd.so and libstd.a
librwtool.so and librwtool.a
libCsup.so and libCsup.a
libstream.so and libstream.a
Using Locks
To guarantee that your I/O results from one thread are not intermingled with I/O results
from other threads, you must protect your I/O statements with locks. For example:
// create a mutex and initialize it
pthread_mutex_t the_mutex;
#ifdef _PTHREADS_DRAFT4 // for user threads
pthread_mutex_init(&the_mutex, pthread_mutexattr_default);
#else // for kernel threads
pthread_mutex_init(&the_mutex, (pthread_mutexattr_t *)NULL);
#endif
pthread_mutex_lock(&the_mutex);
cout << something ... ;
pthread_mutex_unlock(&the_mutex);
Note that conditional compilation may be necessary to accommodate both the user
threads and the kernel threads interfaces, as in the above example. An alternative might
be to compose a buffer with an ostrstream and output with one write. The following
example could be used with the cfront compatiblelibstream:
ostrstream ostr;
ostr << something /*...*/ ;
ostr << or another /*...*/ << endl;
cout.write(ostr.str(), ostr.pcount());
ostr.rdbuf()->freeze(0);
Note that the above example works with the new library, though with the deprecated
ostrstream.
Or something similar can be done with the Rogue Wave Standard C++ Library 2.2.1
(libstd_v2) with standard ostringstream, as in the following example:
ostringstream ostr;
ostr << something /*...*/ ;
214 Exception Handling