Win 32 multithreading 2 getexltcodethread

Source: Internet
Author: User

// 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.
**************************************** **************************************** */

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.