这是一个说明我的问题的最小示例
测试.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
哪个然后将其传递给线程?