What is the correct argument to pthread_create

后端 未结 1 1469
误落风尘
误落风尘 2021-01-22 01:46

I have seen the documentation of pthread_create

In the example at the bottom they are using:

pthread_create(&tinfo[tnum].thread_id, &attr, &t         


        
1条回答
  •  盖世英雄少女心
    2021-01-22 02:24

    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.

    0 讨论(0)
提交回复
热议问题