【发布时间】:2012-07-11 02:12:47
【问题描述】:
这是一个说明我的问题的最小示例
test.c:
#include <stdio.h>
#include <pthread.h>
#define CORES 8
pthread_t threads [ CORES ];
int threadRet [ CORES ];
void foo ()
{
printf ("BlahBlahBlah\n" );
}
void distribute ( void ( *f )() )
{
int i;
for ( i = 0; i < CORES; i++ )
{
threadRet [ i ] = pthread_create ( &threads [ i ], NULL, f, NULL );
}
for ( i = 0; i < CORES; i++ )
{
pthread_join ( threads [ i ], NULL );
}
}
int main ()
{
distribute ( &foo );
return 0;
}
Vim/gcc 输出:
test.c:20|11| warning: passing argument 3 of ‘pthread_create’ from incompatible pointer type [enabled by default]
/usr/include/pthread.h:225|12| note: expected ‘void * (*)(void *)’ but argument is of type ‘void (*)()’
我需要添加/删除什么& 才能将foo 传递给distribute,然后将其传递给线程?
【问题讨论】:
标签: c multithreading gcc pthreads