相关疑难解决方法(0)

Linux中对pthread_create的未定义引用

我从网上从https://computing.llnl.gov/tutorials/pthreads/上摘下了以下演示

#include <pthread.h>
#include <stdio.h>
#define NUM_THREADS     5

void *PrintHello(void *threadid)
{
   long tid;
   tid = (long)threadid;
   printf("Hello World! It's me, thread #%ld!\n", tid);
   pthread_exit(NULL);
}

int main (int argc, char *argv[])
{
   pthread_t threads[NUM_THREADS];
   int rc;
   long t;
   for(t=0; t<NUM_THREADS; t++){
      printf("In main: creating thread %ld\n", t);
      rc = pthread_create(&threads[t], NULL, PrintHello, (void *)t);
      if (rc){
         printf("ERROR; return code from pthread_create() is %d\n", rc);
         exit(-1);
      }
   }
   pthread_exit(NULL);
}
Run Code Online (Sandbox Code Playgroud)

但是当我在我的机器上编译它(运行Ubuntu Linux 9.04)时,我收到以下错误:

corey@ubuntu:~/demo$ gcc -o term term.c …
Run Code Online (Sandbox Code Playgroud)

c linux multithreading pthreads

349
推荐指数
9
解决办法
57万
查看次数

标签 统计

c ×1

linux ×1

multithreading ×1

pthreads ×1