pthread를 만들려고하는데 인수를 만드는 데 필요한 인수가 혼란 스럽습니다.pthread_create가 인수를 허용하지 않습니다.
pthread에 대한 입력 함수에 여러 인수를 전달하려고하고 있는데이를 구조체에 캡슐화했습니다. 그러나 pthread_create
은 허용하지 않습니다. 여기
Customer_Spawn_Params
구조체 여기
Customer_Spawn_Params *params = (Customer_Spawn_Params*) malloc(sizeof(Customer_Spawn_Params));
params->probability = chance;
params->queue = queue;
pthread_t customer_spawn_t;
if (pthread_create(&customer_spawn_t, NULL, enqueue_customers, ¶ms)) {
}
하고 마지막으로
typedef struct {
Queue *queue;
double probability;
} Customer_Spawn_Params;
, 여기 Customer_Spawn_Params
구조체에 대한 포인터를 받아들이는 enqueue_customers()
입니다 :
void *enqueue_customers(Customer_Spawn_Params *params) {
int customer_id = 0;
double probability = params->probability;
Queue *queue = params->queue;
while(true) {
sleep(1);
bool next_customer = next_bool(probability);
if (next_customer) {
Customer *customer = (Customer*) malloc(sizeof(Customer));
customer->id = customer_id;
enqueue(queue, customer);
customer_id++;
}
}
return NULL;
}
'그러나, pthread_create는 그것을 받아들이지 않습니다 .'...이 결론에 어떻게 도달 했습니까? –
'pthread_create'를 호출 할 때 마지막 인자 (쓰레드 함수에 대한 인자)를 포인터 *로 전달합니다. 스레드 함수를 변경하지 않으면 [* undefined behavior *] (http://en.wikipedia.org/wiki/Undefined_behavior)가됩니다. –
매개 변수를 (void *)로 캐스팅하고 스레드 proc가 void를 허용해야합니다. * – dvhh