相关疑难解决方法(0)

pthread 中函数的参数数量

在 pthread 的 hello world 示例中指出:

#include <pthread.h>
#include <stdio.h>

void * print_hello(void *arg)
{
  printf("Hello world!\n");
  return NULL;
}

int main(int argc, char **argv)
{
  pthread_t thr;
  if(pthread_create(&thr, NULL, &print_hello, NULL))
  {
    printf("Could not create thread\n");
    return -1;
  }

  if(pthread_join(thr, NULL))
  {
    printf("Could not join thread\n");
    return -1;
  }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

正如你所看到print_hellopthread_create(),没有参数,但是在定义中,它看起来像void * print_hello(void *arg)

这意味着什么?

现在假设我有这个实现

void * print_hello(int a, void *);
int main(int argc, char **argv)
{
  pthread_t thr;
  int a …
Run Code Online (Sandbox Code Playgroud)

c pthreads

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

标签 统计

c ×1

pthreads ×1