美文网首页
C语言多线程示例

C语言多线程示例

作者: 一路向后 | 来源:发表于2020-07-22 21:54 被阅读0次

1.程序源码

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

void *run(void *arg)
{
    char *buf = (char *)arg;

    printf("%s\n", buf);

    return NULL;
}

int main()
{
    pthread_t p = 0;

    pthread_create(&p, NULL, run, "hello world");

    pthread_join(p, NULL);

    return 0;
}

4.编译源码

$ gcc -o run run.c -lpthread

5.运行程序

$ ./run
hello world

相关文章

网友评论

      本文标题:C语言多线程示例

      本文链接:https://www.haomeiwen.com/subject/lmhxlktx.html