Skip Navigation Links | |
Exit Print View | |
![]() |
Oracle Solaris Studio 12.3: C++ User's Guide Oracle Solaris Studio 12.3 Information Library |
3. Using the C++ Compiler Options
6. Creating and Using Templates
9. Improving Program Performance
10. Building Multithreaded Programs
10.2 Using Exceptions in a Multithreaded Program
10.3 Sharing C++ Standard Library Objects Between Threads
10.4 Memory Barrier Intrinsics
12. Using the C++ Standard Library
All libraries shipped with the C++ compiler are multithreading safe. If you want to build a multithreaded application, or if you want to link your application to a multithreaded library, you must compile and link your program with the –mt option. This option passes –D_REENTRANT to the preprocessor and passes –lthread in the correct order to ld. By default, the -mt option ensures that libthread is linked before libCrun. Use of —mt is recommended as a simpler and less error-prone alternative to specifying the macro and library.
You can check whether an application is linked to libthread by using the ldd command:
example% CC -mt myprog.cc example% ldd a.out libm.so.1 => /usr/lib/libm.so.1 libCrun.so.1 => /usr/lib/libCrun.so.1 libthread.so.1 => /usr/lib/libthread.so.1 libc.so.1 => /usr/lib/libc.so.1 libdl.so.1 => /usr/lib/libdl.so.1
The C++ support libraries, libCrun, libiostream, and libCstd are multithread safe but are not async safe. Therefore, in a multithreaded application, functions available in the support libraries should not be used in signal handlers. Doing so can result in a deadlock situation.
It is not safe to use the following features in a signal handler in a multithreaded application:
Iostreams
new and delete expressions
Exceptions