有没有可能的方法在类中使用线程,如下所示:
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)
我需要提一下,我是线程的新手。我只需要一个想法,这样我就可以开始思考它是如何运作的。