void ポインターまたは int との間でどのように/なぜ変換するのですか?
次のコードは、コンパイラ エラーを誤って生成します。
while(num_producers > 0) {
pthread_t tid; // id of pthread (not used except to call pthread_create)
pthread_attr_t attr; // pthread attributes (not used except to call pthread_create)
pthread_attr_init(&attr); // default pthread attributes
pthread_create(&tid, &attr, producer, num_producers);
num_producers--;
}
次のエラーが表示されます (すべて pthread_create 行にあります)。
error: invalid conversion from 'void (*)(int)' to 'void* (*)(void*)'
error: initializing argument 3 of 'int pthread_create(_opaque_pthread)t**, const pthread_attr_t*, void* (*)(void*), void*)'
error: invalid conversion from 'int' to 'void*'
error: initializing argument 4 of 'int pthread_create(_opaque_pthread_t**, const pthread_attr_t*, void* (*)(void*), void*)'
メインと同じファイルに含まれる関数「プロデューサー」のみを実行する pthread を作成したいと考えています。なぜこれが機能しないのですか?