// Exitcode. c
# Include <stdio. h>
# Include <stdlib. 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 ");
}
// Keep waiting untill both callto
// Getexitcodethread succeed and
// Neither of them returns still_active
For (;;)
{
Printf ("press any key to exit/N ");
Getch ();
Int N;
N = getexitcodethread (hthrd1, & exitcode1 );
N = getexitcodethread (hthrd2, & exitcode2 );
If (exitcode1 = still_active)
{
Puts ("thread 1 is still running/N ");
}
If (exitcode2 = still_active)
{
Puts ("thread 2 is still running/N ");
}
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 * 10000*2 );
Return (DWORD) N * 10;
}
/*************************************** **************************************** **
Bool getexltcodethread (
Handle hthread,
Lpdword lpexitcode
);
Handle Of The hthread returned by createthread ()
Lpexitcode points to DWORD to accept the end code
Return Value:
If the request is successful, true is returned. Otherwise, false is returned. getlasterror () is called to identify the cause.
If the thread has ended, the end code is included in the lpexitcode parameter.
If the thread has not ended, the value brought back by lpexitcode is still_active.
**************************************** **************************************** */