函数参数在Linux编程中用于Pthread调度API

时间:2016-12-04 14:15:11

标签: c linux operating-system pthreads

在Pthread Scheduling API for Operating Systems课程上进行分配。我遇到了一个看起来像这样的函数:

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

有人可以解释第二个最后一个函数参数在语法方面的含义吗?即

   void *(*start_routine) (void *)

1 个答案:

答案 0 :(得分:1)

void *(*start_routine) (void *)是一个指向函数的指针,该函数将void*作为参数并返回void*

通常,您可以使用cdecl.org来读取复杂的C声明。对于void *(*start_routine) (void *),它说:

  

将start_routine声明为函数指针(指向void的指针)   返回指向void的指针

在Pthreads中,作为参数传递给pthread_create()的函数指针是线程函数,它在pthread_create()调用成功后运行(取决于操作系统调度的方式)。

请参阅here for a simple example如何使用pthread_create()和线程函数。