int pthread_create(pthread_t * thread, pthread_attr_t *
attr, void * (*start_routine)(void *), void * arg);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
這到底是指什麼意思呢?
連用法都不只一種說...(如下)
第一種:
void print_message_function( void *ptr );
.
.
.
pthread_t thread1;
char *message1 = "Hello";
pthread_create( &thread1, pthread_attr_default,
(void*)&print_message_function, (void*) message1);
第二種:
void print_message_function( void *ptr );
.
.
.
pthread_t thread1;
char *message1 = "Hello";
pthread_create( &thread1, pthread_attr_default,
(void*)print_message_function, (void*) message1);
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>
--
* Origin: ★ 交通大學資訊科學系 BBS ★ <bbs.cis.nctu.edu.tw: 140.113.23.3>
傳名呼叫吧…很多C語言的書都有…
你標起來的那一段大概是說…
pthread_create會傳入一函數,此函數有一void指標的參數…而且會傳回一void指標…
…這個程式是在做什麼的呀?
傳回型態為void *的函數 .也就是說 用這樣的方式來呼叫 pthread_create:
int_number=pthread_create(參數一,參數二,ld(參數三),參數四);
其中ld()需為先宣告為一void*(*ld)(void*)並初始化指向一型態相同的函數
或者也可以寫成pthread_create(參數一,參數二,void*(*ld)(void*)=cl(參數三),
參數四);
其中 要先宣告 void *cl(void*);
ps:呼叫中的ld(參數三)也可以寫成(*ld)(參數三)
--
歡迎大家鬥陣來飲茶...
Ξ Origin: 中興大學天樞資訊網 <b...@bbs.nchu.edu.tw> [FROM: sysnux.ev.nchu.]