RAD Studio
ContentsIndex
PreviousUpNext
Multithread Programs

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 library instead. 

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

  • _beginthread
  • _beginthreadex
  • _beginthreadNT
The multithread libraries also provide the following corresponding functions that terminate threads:
  • _endthread
  • _endthreadex
  • _threadid a global variable that contains the current identification number of the thread also known as the thread ID).
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:

BCC32 -tWM THREAD.C

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.

Copyright(C) 2009 Embarcadero Technologies, Inc. All Rights Reserved.
What do you think about this topic? Send feedback!