#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