zoukankan      html  css  js  c++  java
  • 好玩 多线程 显示

    // 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;
    }
    

      

  • 相关阅读:
    spark
    mongdb
    redis
    mysql
    kylin
    kafka
    hadoop+hive+hbase+kylin
    git
    elasticsearch
    clickhouse
  • 原文地址:https://www.cnblogs.com/mathzzz/p/2661285.html
Copyright © 2011-2022 走看看