Multithread Programs

From RAD Studio
Jump to: navigation, search

Go Up to C Run-Time Library Reference

Win32 programs can create more than one thread of execution. If your program creates multiple threads, and these threads also use the C++ runtime library, you must use the CW32MT.LIB or CW32MTI.LIB library instead.

The multithread libraries provide the following functions which you use to create threads:

The multithread libraries also provide the following corresponding functions that terminate threads:

The header file stddef.h contains the declaration of _threadid.

When you compile or link a program that uses multiple threads, you must use the -tWM compiler switch. For example:


Note: Take special care when using the signal function in a multithread program. The SIGINT, SIGTERM, and SIGBREAK signals can be used only by the main thread (thread one) in a non-Win32 application. When one of these signals occurs, the currently executing thread is suspended, and control transfers to the signal handler (if any) set up by thread one. Other signals can be handled by any thread.A signal handler should not use C++ runtime library functions, because a semaphore deadlock might occur. Instead, the handler should simply set a flag or post a semaphore, and return immediately.

See Also