linux c多线程编程范例


#include <stdio.h>
#include <pthread.h>
#include <unistd.h>
#include <stdlib.h>

void* func_1(void* args)
{
    while(1){
        sleep(1);
        printf("this is func_1!\n");
    }
}

void* func_2(void* args)
{
    while(1){
        sleep(2);
        printf("this is func_2!\n");
    }
}

int main()
{
    pthread_t pid1, pid2;

    if(pthread_create(&pid1, NULL, func_1, NULL))
    {
        return -1;
    }

    if(pthread_create(&pid2, NULL, func_2, NULL))
    {
        return -1;
    }

    while(1){
        sleep(3);
    }

    return 0;
}

编译命令:gcc thread.c -o thread -lpthread

优质内容筛选与推荐>>
1、硬件自检
2、一周学习总结
3、HIVE提交command过程图
4、orm框架分析——仿优酷项目
5、RCFileInputFormat的使用方法


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号