众所周知,如何使用线程。但是线程库是怎么实现的。我的意思是,就像我们有 std::string
,它的功能可以在某种程度上被复制,由用户自己使用 C 字符串(字符数组),这很容易。
我的问题是如何在线程的情况下实现这一点,比如我如何创建一个具有最低限度 C++ 数据类型和函数(没有 WINAPI)的类,std::thread 类功能到一个类中。
我想举个例子,我的老师禁止我使用 std::string,只允许使用 C 字符串,但我可以使用 OOP 概念..
class string_my
{
private:
char* str;
public:
// all the required func. to store the value in char*
}
最佳答案
如果不使用操作系统提供的线程原语或某些更高级别的线程库(如 boost::thread
或 std::thread
),则无法实现线程类反过来依赖于所述操作系统提供的线程原语。
关于c++ - 线程构造的幕后,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47056962/