在c ++中使用pthread [英] using pthread in c++

查看:190
本文介绍了在c ++中使用pthread的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 *。cc 文件中使用 pthread.h 当我尝试使用 pthread_exit(0); pthread_join(mythrds [yy],NULL);

  .cc :(。text + 0x3e):未定义引用`pthread_exit'

当在一个 *。c 文件中编译非常类似的代码,如何在c ++中使用pthread's(我也添加了-lpthread)

  .. 
void * myThreads void * ptr)
{
...
pthread_exit(0);
}
..

标志:

  g ++ -lpthread -Wall -static -W -O9 -funroll-all-loops -finline -ffast-math 


解决方案

您可以尝试对g ++使用-pthread选项。

  -pthread 
添加对pthreads库的多线程支持。这个
选项为预处理器和链接器设置标志。


I am using pthread.h in a *.cc file. when I try to use pthread_exit(0); or pthread_join(mythrds[yy],NULL); it says:

.cc:(.text+0x3e): undefined reference to `pthread_exit'

when complied very similar code in a *.c file with gcc it work perfect. How Can I use pthread's in c++.. (I also added -lpthread)

..
void *myThreads ( void *ptr )
{
...
pthread_exit(0); 
}
..

flags:

g++ -lpthread -Wall -static -W -O9 -funroll-all-loops -finline -ffast-math

解决方案

You might try using the -pthread option to g++.

   -pthread
       Adds support for multithreading with the pthreads library.  This
       option sets flags for both the preprocessor and linker.

这篇关于在c ++中使用pthread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆