A small example of the oncoming

Source: Internet
Author: User

#include <stdio.h>#include<windows.h>DWORD WINAPI ThreadFunc (LPVOID);intMain () {Std::ios::sync_with_stdio (false); HANDLE HTHRD=NULL; DWORD threadId=0; //Unable to predict results, execution order cannot be guaranteed//because task switch can happen at any time     for(inti =0; I <5; ++i) {/*Return two values, the first value is HANDLE, and this is its return value, and the thread-related API is related to it HANDLE CreateThread (lpsecurity_attuibutes
Ipthreadattributes,//New Thread security attribute (NULL means default) DWORD Dwstacksize,//new thread default stack size Lpthread_st Art_routine
Ipstartaddress,//start address of new thread, hold a pointer lpvoid ipparameter,//This value will be passed in the new thread as parameter DWORD Dwcreatinflags,//allows a temporarily suspended thread to be generated, the default is to immediately start executing Lpdword ipthreadid//New thread ID, is a global variable, can be unique to represent any process of the system of a thread); */ //New ThreadHTHRD =CreateThread (NULL,0, ThreadFunc, (LPVOID) I,0, &threadId); //Main Thread if(HTHRD) {printf ("Thread launched%d \ n", i); } } //wait for thread hthrd to prevent it from ending prematurelySleep ( -); returnexit_success;} DWORD WINAPI ThreadFunc (lpvoid N) { for(inti =0; I <Ten; ++i) {printf ("%d%d%d%d%d%d%d%d\n", N, N, N, N, N, N, N, N); } return 0;}

A small example of the oncoming

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.