Ubuntu下看不见pthread_create(安装pthread线程库)

使用下面的命令就可以了!

sudo apt-get install glibc-doc

sudo apt-get install manpages-posix-dev

然后在用man -k pthread_create就可以找到了。

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ubuntu下,使用C语言的pthread_create函数来创建线程。pthread_create的函数原型如下: ```c int pthread_create(pthread_t *thread, const pthread_attr_t *attr, void *(*start_routine)(void*), void *arg); ``` 其中,thread是一个指向pthread_t类型的指针,用于存储新线程的标识符; attr是一个指向pthread_attr_t类型的指针,用于设置线程的属性(通常为NULL,表示使用默认属性); start_routine是指向函数的指针,该函数将作为新线程的起始点; arg是一个指向void类型的指针,用于向start_routine函数传递参数; 函数的返回值为0表示成功创建线程,其他值表示错误。 下面是一个例子,演示了如何在Ubuntu下使用pthread_create函数创建线程: ```c #include <stdio.h> #include <pthread.h> void *thread_func(void *arg) { int thread_id = *(int *)arg; printf("Hello from thread %d\n", thread_id); pthread_exit(NULL); } int main() { pthread_t thread; int thread_id = 1; pthread_create(&thread, NULL, thread_func, (void *)&thread_id); pthread_join(thread, NULL); return 0; } ``` 这个例子中,定义了一个名为thread_func的函数作为新线程的起始点。在主函数中,调用pthread_create函数来创建一个新线程,并将thread_func函数作为参数传递给pthread_create函数。在thread_func函数中,打印出线程的ID,并使用pthread_exit函数来终止线程。最后,使用pthread_join函数来等待新线程完成。 请注意,上述代码只是一个示例,你可以根据自己的需求对线程进行定制和调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值