c++ _beginthread
c++多线程编程
1 #include <windows.h> 2 #include <process.h> /* _beginthread, _endthread */ 3 #include <iostream> 4 5 using namespace std; 6 7 void show(void *ptr); 8 9 int main(){ 10 _beginthread(show, 0, NULL); 11 Sleep(50000); 12 return 0; 13 } 14 15 void show(void *ptr){ 16 int i = 0; 17 cout<<"i am in"<<endl; 18 while(++i){ 19 if(10 == i){ 20 _endthread(); 21 } 22 cout<<"i = "<<i<<endl; 23 Sleep(1000); 24 } 25 26 }
用__beginthread开始线程,用_endthread结束线程
ps:下面来自百度百科
uintptr_t _beginthread(
void( *start_address )( void * ),
unsigned stack_size,
void *arglist
);
这个是_beginthread()函数原型
参数:
Please call me JiangYouDang!