有没有办法访问thread.h
文件。
我无法在 Windows 中找到 thread.h header ,因为线程与操作系统有关。
我尝试使用外部库 pthread.h,但从未找到据我的教授在 solaris 中工作的 thread.h。
最佳答案
这是一个很好的例子,其中用“C”和“C++”标记问题会非常困惑,因为答案完全不同。
如果您使用 C++11 或更高版本进行编码,那么您应该
#include <thread>
并使用 std::thread
类。你会没事的。
如果您使用 C11 或更高版本进行编码,那么您应该
#include <threads.h>
但是,您可能必须等到您的实现支持它。 C11 标准的 § 7.26.1 ¶ 2 说:
Implementations that define the macro
__STDC_NO_THREADS__
need not provide this header nor support any of its facilities.
您可以使用 #ifdef
检查您的实现是否定义了它。至少我的 GCC 是这样。
目前,如果您不能切换到 C++,请使用第三方线程库,如 pthreads。
关于c - fatal error : thread. h:没有那个文件或目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33092197/