2016-12-04 53 views
0

在Pthread Scheduling API for Operating Systems課程上進行分配時。我碰到一個看起來像這樣的函數:Linux中的函數參數含義Pthread Scheduling API編程API

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

有人能解釋第二個最後的函數參數在語法方面意味着什麼嗎?即

void *(*start_routine) (void *) 

回答

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()和線程函數。