首页 > 代码库 > c++ _beginthread

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结束线程

c++ _beginthread