zoukankan      html  css  js  c++  java
  • pthread_create创建线程

    #include <stdio.h>
    #include <pthread.h>
    
    void *pthread_fun(void *arg)
    {
    	while (1) {
    		sleep(1);
    		printf("pthread running\n");
    	}
    
    	return((void *)0);
    }
    
    int main()
    {
    	pthread_t tid;
    	pthread_create(&tid, NULL, pthread_fun, NULL);
    //	pthread_create(&tid, NULL, &pthread_fun, NULL);
    
    	while (1) {
    		sleep(2);
    		printf("main runing\n");
    	}
    	return 0;
    }

    编译 gcc test.c -lpthread

  • 相关阅读:
    9
    8
    7
    6
    5
    第四周
    作业14-数据库
    作业13-网络
    作业12-流与文件
    作业11-多线程
  • 原文地址:https://www.cnblogs.com/helloweworld/p/2774851.html
Copyright © 2011-2022 走看看