10个线程并且启动它

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*----------------------------------------------------------------------------*/
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);
 
}

  

posted on   lydstory  阅读(395)  评论(0编辑  收藏  举报

编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
历史上的今天:
2019-08-03 QMap的key也可以是一个结构体类吗?

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示