在 C++ 中使用 pthread [英] Using pthread in c++

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

问题描述

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

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'

当使用 gcc 在 *.c 文件中编译非常相似的代码时,它可以完美运行.如何在 c++ 中使用 pthread ..(我还添加了 -lpthread)

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); 
}
..

标志:

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

推荐答案

您可以尝试使用 g++ 的 -pthread 选项.

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天全站免登陆