作为一项任务的一部分,我正在尝试创建一个像pthreads这样的用户级线程库.
为了处理线程之间的上下文切换,我使用'swapcontext'函数.在使用它之前,我必须使用'makecontext'函数创建一个上下文.'makecontext'需要一个带返回类型void和参数类型的函数指针(void).
然而,线程函数必须是类型 void* thread_func (void*)
有没有办法进行类型转换?或者是否有其他方法在用户级别进行上下文切换?
我正在传递一个 int pthread_create 类型的数组并收到错误:
histogram.c:138:3: warning: passing argument 3 of
‘pthread_create’ from incompatible pointer type [enabled by default]
expected ‘void * (*)(void *)’ but argument is of type ‘void * (*)(int *)’
void *output_results();
pthread_create(&t2, NULL, output_results, (void *)bins);
void *output_results(int *bins) {
some code
}
Run Code Online (Sandbox Code Playgroud)