什么是pthread_create的正确说法 [英] What is the correct argument to pthread_create

查看:155
本文介绍了什么是pthread_create的正确说法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我见过 pthread_create的

在在它们所使用的底部的示例:

 在pthread_create(安培; TINFO [tnum] .thread_id,&安培; attr指示,&安培; thread_start,&安培; TINFO [tnum]);

&放大器; thread_start - 以&安培;

但在其他的例子我已经在网上看到他们​​没有使用&安培;

 在pthread_create(安培; TINFO [tnum] .thread_id,&安培; attr指示,thread_start,&安培; TINFO [tnum]);

我也测试和它的作品没有&放大器;

不过,这是正确的方式?


解决方案

简短的回答:两者都是正确的。


在pthread_create 的签名是:

  INT在pthread_create(*的pthread_t线程,常量pthread_attr_t * ATTR,
                      无效*(*的start_routine)(无效*),无效* ARG);

所以的start_routine 是一个函数指针,它接受一个无效* 参数并返回无效*

回到你的问题,我认为 thread_start 是函数的名字,所以&放大器; thread_start 是一个函数指针这是正确的。

然而, thread_start 是正确的,也因为函数名被自动转换为一个函数指针。

I have seen the documentation of pthread_create

In the example at the bottom they are using:

pthread_create(&tinfo[tnum].thread_id, &attr, &thread_start, &tinfo[tnum]);

&thread_start - with &

but in other examples I have seen online they were not using the &:

pthread_create(&tinfo[tnum].thread_id, &attr, thread_start, &tinfo[tnum]);

I have also tested and it works without &.

But which is the correct way?

解决方案

Short answer: both are correct.


The signature of pthread_create is:

int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
                      void *(*start_routine) (void *), void *arg);

So start_routine is a function pointer that takes a void * argument and returns void *.

Back to your question, I assume thread_start is the name of the function, so &thread_start is a function pointer which is correct.

However, thread_start is correct, too, because the function name is automatically converted to a function pointer.

这篇关于什么是pthread_create的正确说法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆