#define WIN32_LEAN_AND_MEAN
#include <stdlib.h>
#include <stdio.h>
#include <windows.h>
#include <conio.h>
DWORD WINAPI ThreadFunc(LPVOID);
int main()
{
HANDLE hThrd1;
HANDLE hThrd2;
DWORD exitcode1 = 0;
DWORD exitcode2 = 0;
DWORD threadId;
hThrd1 = CreateThread(
NULL,
0,
ThreadFunc,
(LPVOID)1,
0,
&threadId);
if (hThrd1)
{
printf("Thread 1 launched/n");
}
hThrd2 = CreateThread(
NULL,
0,
ThreadFunc,
(LPVOID)2,
0,
&threadId);
if (hThrd2)
{
printf("Thread 2 launched/n");
}
for (;;)
{
printf("Press any key to exit./n");
getch();
GetExitCodeThread(hThrd1, &exitcode1);
GetExitCodeThread(hThrd2, &exitcode2);
if (exitcode1 == STILL_ACTIVE)
{
puts("Thread 1 is still running!");
}
if (exitcode2 == STILL_ACTIVE)
{
puts("Thread 2 is still running!");
}
if (exitcode1 != STILL_ACTIVE && exitcode2 != STILL_ACTIVE)
{
break;
}
}
CloseHandle(hThrd1);
CloseHandle(hThrd2);
printf("Thread 1 returned %d/n", exitcode1);
printf("Thread 2 returned %d/n", exitcode2);
return EXIT_SUCCESS;
}
DWORD WINAPI ThreadFunc( LPVOID n)
{
Sleep((DWORD)n*1000*2);
return (DWORD)n*10;
}