linux C函数指针的问题,编译报警告
本帖最后由 zhoujiawen 于 2013-01-15 15:09:23 编辑 在gcc下编程,创建多个线程,想将这些线程地址都放在一个指针数组里,
//5个线程的声明
void *thread_1(void *arg);
void *thread_2(void *arg);
void *thread_3(void *arg);
void *thread_4(void *arg);
void *thread_5(void *arg);
//这里想将所有的线程名都放在一个数组里,便于管理
void (*init_thread[ ])(void *) = {
thread_1,
thread_2,
thread_3,
thread_4,
thread_5
};
pthread_t id[5];//线程id
for (i=0; i<MAX_THREAD_CLIENT; i++) {//通过循环的方式实现创建线程
counts = 0;
while(pthread_create(&id[i], NULL, init_thread[i], NULL)) {//创建线程
if (counts++ > 100) {
fprintf(stderr, "thread[%d]: failed to create\n", i);
exit(EXIT_FAILURE);
}
}
counts = 0;
while(pthread_join(id[i], NULL)) {//加入线程
if (counts++ > 100) {
fprintf(stderr, "thread[%d]: failed to join\n", i);
exit(EXIT_FAILURE);
}
}
}