MultiThread
Borland C++ Compiler 5.5
makefile
CFLAGS = -WM
mttest.c
#include
#include
#include
unsigned __stdcall ThreadFunc(void *pv); static int l_iFlag = 0; int main() { HANDLE hThread; u_int uiThrdAddr; DWORD dwExitCode; hThread = (HANDLE)_beginthreadex(NULL, 0, ThreadFunc, NULL, 0, &uiThrdAddr); if (hThread == 0) { fprintf(stderr, "_beginthreadex\n"); return 1; } scanf("%*c"); l_iFlag = 1; WaitForSingleObject(hThread, INFINITE); if (GetExitCodeThread(hThread, &dwExitCode)) { printf("ExitCode = %u\n", dwExitCode); } CloseHandle(hThread); return 0; } unsigned __stdcall ThreadFunc(void *pv) { int i; for (i = 0; i < 10; i++) { printf("%d\n", i); Sleep(1000); if (l_iFlag) { break; } } // _endthreadex(10); return 20; }