相关疑难解决方法(0)

输入void void*(*)(void*)为void(*)(void)

作为一项任务的一部分,我正在尝试创建一个像pthreads这样的用户级线程库.

为了处理线程之间的上下文切换,我使用'swapcontext'函数.在使用它之前,我必须使用'makecontext'函数创建一个上下文.'makecontext'需要一个带返回类型void和参数类型的函数指针(void).

然而,线程函数必须是类型 void* thread_func (void*)

有没有办法进行类型转换?或者是否有其他方法在用户级别进行上下文切换?

c multithreading casting pthreads

4
推荐指数
1
解决办法
2020
查看次数

c pthread传递int类型的数组

我正在传递一个 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)

c arrays pthreads

1
推荐指数
1
解决办法
4287
查看次数

标签 统计

c ×2

pthreads ×2

arrays ×1

casting ×1

multithreading ×1