我创建了 pthread 如下:
void function1(void *s) {
start = (*(int *)s ;
}
pthread_t threads[numthreads];
int ids[numthreads];
for (i = 0; i < numthreads; i++) {
ids[i] = i;
int * p = &ids[i] ;
pthread_create(&threads[i], NULL, function1, (void *)p);
}
Run Code Online (Sandbox Code Playgroud)
但这给了我错误:
>> mpicc -o hprogram hprogram.c
warning: incompatible pointer types passing 'void (void *)' to
parameter of type 'void * _Nullable (* _Nonnull)(void * _Nullable)'
[-Wincompatible-pointer-types]
pthread_create(&threads[i], NULL, function1, (void *)...
^~~~~~~~~~
/usr/include/pthread.h:328:31: note: passing argument to parameter here
void * _Nullable (* _Nonnull)(void * _Nullable),
^
1 warning generated.
Run Code Online (Sandbox Code Playgroud)
这是一个mpi程序,我使用pthreads创建了一个混合mpi。
pthread_create()期望一个指向一个函数的指针,该函数将 avoid*作为输入并返回 avoid*作为输出,但您的函数返回 avoid代替。您只需要*在返回类型中添加一个,并添加一个return语句,例如:
void* function1(void *s) {
start = *(int *)s;
return NULL; // <-- or whatever you want
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1797 次 |
| 最近记录: |