【发布时间】:2013-02-24 22:21:42
【问题描述】:
我的 ThreadData 结构:
typedef struct threadData {
pthread_t *ths;
} threadData;
其中 *ths 是 pthread_t 的数组。
现在,我创建一个线程,使用以下函数作为操作,该函数在 ths[1] 中创建一个新线程
void *rootThread(threadData *d) {
pthread_t *b = (*d).ths;
pthread_create(*(b+1),NULL,someRandomFunction,NULL);
}
但这似乎不起作用。
我不确定我是否很好地取消了 pthread_t 元素的引用。请帮忙!
谢谢,:)。
【问题讨论】:
-
你是如何分配你的结构踏面数据的?目前,您似乎正在创建线程数据的成员,只是为了作为指针,而不为它分配内存。 rootThread 获得一个指向 threadData 的指针。所以用它作为 pthread* b = d->ths 进一步 pthread_create 想要一个指向 pthread_t 的指针,因此不要取消它。
标签: c struct pthreads dereference