The following HP aC++ libraries are thread-safe:
libstd.sl and libstd.a
librwtool.sl and librwtool.a
libCsup.sl libCsup.a
libstream.sl libstream.a
In order to pick the thread safe version of I/O routines (cout, cin, cerr, and clog) when you include iostream.h in your source files, you can add the -D_THREAD_SAFE compile time flag to your compilation line.
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 statement with locks. (Note, if you use locks, you do not have to use the -D_THREAD_SAFE compile time flag.) For example:
Note that conditional compilation may be necessary to accomodate both the user threads and the kernel threads interfaces, as in the above example.
WARNING: If you do not specify these options, a run-time error will be generated or multi-thread behavior will be incorrect.
-D__HPACC_THREAD_SAFE_RB_TREErb_tree class is involved.
In other words, if the tree header file
(which includes tree.cc) under /opt/aCC/include/ is used,
these libraries are not thread safe.
Most likely, it is indirectly referenced by including the standard C++ library
container class map or set headers,
or by including a RogueWave tools.h++ header like tvset.h,
tpmset.h, tpmset.h, tvset.h, tvmset.h, tvmset.h, tpmap.h, tpmmap.h,
tpmmap.h, tvmap.h, tvmmap.h.
Since changing the current rb_tree implementation to
make it thread safe would break binary compatibility,
the preprocessing macro, __HPACC_THREAD_SAFE_RB_TREE, must be defined.
Whether or not this macro is defined
when compiling a file that includes the tree header, its use must
be consistent. For example, a new object file compiled with the macro
defined should not be linked with older ones that were compiled without
the macro defined. Library providers whose library is built with the
the macro defined may need to notify their users to also compile their source
with the macro defined when the tree header is included.
The following example illustrates that you cannot catch an object which has been thrown in a different thread. To do so will result in a runtime abort since HP aC++ finds no available catch handler and terminate is called.
#include <pthread.h>
void foo() {
int i = 10;
throw i;
}
int main() {
pthread_t tid;
try {
ret=pthread_create(&tid, 0, (void*(*)(void*))foo, 0);
}
catch(int n) {}
}