【发布时间】:2015-11-17 15:58:14
【问题描述】:
我希望我的每个线程调用多个函数。我怎样才能做到这一点?现在我有只调用一个函数的线程代码:
pthread_attr_init(&attributes);
if((tid1 = pthread_create(&thread[0],&attributes,produce,NULL)))
{
printf("\nError in the producer thread\n");
printf("\n");
}
if((tid2 = pthread_create(&thread[1],&attributes,consume,NULL)))
{
printf("\nERror in the consumer thread\n");
}
pthread_join(thread[0],NULL);
pthread_join(thread[1],NULL);
调用 pthread_create 会产生两个新线程吗?
【问题讨论】:
-
你传递给
pthread_create的函数就像main给你的程序:它的起点。然后,您可以将您想要的任何内容作为代码放入此函数中......您的问题是什么? -
我想我不明白的是如何在 pthread_create 中放置多个函数。
-
@ballballbobo 你能把一个函数放在另一个函数里面吗?