码迷,mamicode.com
首页 > 编程语言 > 详细

10个线程并且启动它

时间:2020-08-03 09:52:47      阅读:81      评论:0      收藏:0      [点我收藏+]

标签:for   sleep   char   create   ack   启动   10个   run   callback   

/*----------------------------------------------------------------------------*/
void *thread(void *ptr)
{
	   BaseSocks basesock;
	   basesock.run(1,callback);

   return 0;
}

void *thread2(void *ptr)
{
	 BaseSocks basesock;
	 basesock.run(2,callback);
    return 0;
}
void *thread3(void *ptr)
{
	 BaseSocks basesock;
	 basesock.run(3,callback);
    return 0;
}
void *thread4(void *ptr)
{
	 BaseSocks basesock;
	 basesock.run(4,callback);
    return 0;
}
void *thread5(void *ptr)
{
	 BaseSocks basesock;
	 basesock.run(5,callback);
    return 0;
}
void *thread6(void *ptr)
{
	 BaseSocks basesock;
	 basesock.run(6,callback);
    return 0;
}
void *thread7(void *ptr)
{
	 BaseSocks basesock;
	 basesock.run(7,callback);
    return 0;
}

int main(int argc, char **argv)
{

	pthread_t id;
	        int ret = pthread_create(&id, NULL, thread, NULL);
	        if(ret) {

	            return 1;
	        }
	        for(int i = 0;i < 3;i++) {

	            sleep(1);
	        }


	    	pthread_t id2;
	    	        int ret2 = pthread_create(&id2, NULL, thread2, NULL);
	    	        if(ret2) {

	    	            return 1;
	    	        }
	    	        for(int i = 0;i < 3;i++) {

	    	            sleep(1);
	    	        }
	    	    	pthread_t id3;
	    	    	        int ret3 = pthread_create(&id3, NULL, thread3, NULL);
	    	    	        if(ret3) {

	    	    	            return 1;
	    	    	        }
	    	    	        for(int i = 0;i < 3;i++) {

	    	    	            sleep(1);
	    	    	        }

	    	    	    	pthread_t id4;
	    	    	    	        int ret4 = pthread_create(&id4, NULL, thread4, NULL);
	    	    	    	        if(ret4) {

	    	    	    	            return 1;
	    	    	    	        }
	    	    	    	        for(int i = 0;i < 3;i++) {

	    	    	    	            sleep(1);
	    	    	    	        }

	    	    	      	    	pthread_t id5;
	    	    	    	    	    	    	        int ret5 = pthread_create(&id5, NULL, thread5, NULL);
	    	    	    	    	    	    	        if(ret5) {

	    	    	    	    	    	    	            return 1;
	    	    	    	    	    	    	        }
	    	    	    	    	    	    	        for(int i = 0;i < 3;i++) {

	    	    	    	    	    	    	            sleep(1);
	    	    	    	    	    	    	        }
	    	    	    	    	    	    	    	pthread_t id6;
	    	    	    	    	    	    		    	        int ret6= pthread_create(&id6, NULL, thread6, NULL);
	    	    	    	    	    	    		    	        if(ret6) {

	    	    	    	    	    	    		    	            return 1;
	    	    	    	    	    	    		    	        }
	    	    	    	    	    	    		    	        for(int i = 0;i < 3;i++) {

	    	    	    	    	    	    		    	            sleep(1);
	    	    	    	    	    	    		    	        }
	    	    	    	    	    	    		    	    	pthread_t id7;
	    	    	    	    	    	    		    		    	        int ret7= pthread_create(&id7, NULL, thread7, NULL);
	    	    	    	    	    	    		    		    	        if(ret7) {

	    	    	    	    	    	    		    		    	            return 1;
	    	    	    	    	    	    		    		    	        }
	    	    	    	    	    	    		    		    	        for(int i = 0;i < 3;i++) {

	    	    	    	    	    	    		    		    	            sleep(1);
	    	    	    	    	    	    		    		    	        }
	      pthread_join(id, NULL);
	      pthread_join(id2, NULL);
	      pthread_join(id3, NULL);
	      pthread_join(id4, NULL);
	      pthread_join(id5, NULL);
	      pthread_join(id6, NULL);
	      pthread_join(id7, NULL);

}

  

10个线程并且启动它

标签:for   sleep   char   create   ack   启动   10个   run   callback   

原文地址:https://www.cnblogs.com/hshy/p/13424505.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!