Using pthread in c++(在 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C++ 中使用 pthread


- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 从python回调到c++的选项 2022-11-16
- C++ 协变模板 2021-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01