C. source code for creating a new thread

Source: Internet
Author: User

# Include <windows. h>
# Include <stdio. h>

// Thread Functions
DWORD winapi threadproc (lpvoid lpparam)
{
Int I = 0;
While (I <20)
{
Printf ("I am from a thread, Count = % d/N", I ++ );
}
Return 0;
}

int main (INT argc, char * argv [])
{< br> handle hthread;
DWORD dwthreadid;
// create a new thread
hthread = createthread (
null, // Default Security Attribute
null, // default stack size
threadproc, // thread entry address (function of the execution thread)
null, // parameter passed to the function
0, // specify the thread to run immediately
& dwthreadid // return the thread id
);
printf ("now another thread has been created, ID: % d/N ", dwthreadid);
// wait until the new thread finishes running
waitforsingleobject (hthread, infinite); // infinite indicates that the wait duration is infinite, unit: millisecond
closehandle (hthread);
return 0;
}

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.