好玩 多线程 显示

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
// gcc -test.c -lconio -lpthread
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <unistd.h>
#include <string.h>
#include <time.h>
#include <conio.h>
#include <pthread.h>
void act(void *arg)
{
    int i;
    for(i = 0; i<10000; i++){
        gotoxy(10+(int)arg, 10+(int)arg);
        printf("%x:%d",(unsigned int)pthread_self(), i);
        usleep(1000 * 100);
    }
    return;
}
 
  
  
int main(int argc, char *argv[])
{
    setbuf(stdout, NULL);
    pthread_t tid[5];
     
    int i;
    for(i = 0; i< 5; i++)
        pthread_create(tid+i, NULL, act, (void*)i);
 
    for(i=0; i<10000; i++){
        gotoxy(20, 5);
        printf("%d\n", i++);
        usleep(1000 * 30);
    }
 
    for(i = 0; i<5; i++)
        pthread_join(tid+i, NULL);
 
    return 0;
}

  

posted @   庄庄庄  阅读(173)  评论(0编辑  收藏  举报
努力加载评论中...
点击右上角即可分享
微信分享提示