好玩 多线程 显示

// 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 @ 2012-08-29 03:37  庄庄庄  阅读(166)  评论(0编辑  收藏  举报