c语言多线程的并发处理,c语言多线程实现并发处理
终极管理员 知识笔记 128阅读
1, creating and waiting for multiple threads to store multiple thread line objects by means of vectors, and creating and running multiple threads by means ofvector和它的迭代器, The code is as follows: # includediostream # includedthread # includvector using namespace stdvoid myprint (intinum) {cout' myprint thread started to execute, thread number=' inum endlcout 'myprint thread ended to execute, and thread number=' inum endl returned; } int main(){ vector thread mythreads; //Create 10 threads, and the thread entry function uses MyPrint for (int I=0; I 10i) {//Create a thread and start executing mythreads.push _ back (thread (myprint, I));); } for(auto ITER=mythreads . begin(); iter!=myth threads . end(); ITER){ ITER-join(); //Wait for the thread to return} cout' main over' endl returns 0; }
