小编val*_*ian的帖子

如何在C++中的类构造函数中使用线程?

有没有可能的方法在类中使用线程,如下所示:

Class Logger // singleton class
{
//.... here is implemented thread logic 
{

void main()
{
   Logger& log = Logger::getInstance();
   log.writeMessage(); // this should execute in another thread
                       // also, all the other func from Logger class
                       // should execute in that second thread

   // ... some code -> executes in main thread

   log.deleteInstance(); // join threads

}
Run Code Online (Sandbox Code Playgroud)

我需要提一下,我是线程的新手。我只需要一个想法,这样我就可以开始思考它是如何运作的。

c++ multithreading

5
推荐指数
1
解决办法
4638
查看次数

标签 统计

c++ ×1

multithreading ×1