小编I G*_*att的帖子

C++新线程睡眠主线程

运行以下代码:

methodOne(){
    std::thread t(&ChatBubble::runChatBubbleThread, this);
    t.join();
}
Run Code Online (Sandbox Code Playgroud)

runChatBubbleThread:

runChatBubbleThread(){
    // code here
    sleep(2000);
    // more code here    
}
Run Code Online (Sandbox Code Playgroud)

我的理解是新威胁t被创建,执行其代码,然后在主线程完成后加入主线程,有没有理由sleep()在主线程中休眠?

我唯一能想到的就是t.join在主线程继续之前等待线程完成,但是如果它必须等待则最后是线程的重点!

c++ multithreading

0
推荐指数
1
解决办法
953
查看次数

标签 统计

c++ ×1

multithreading ×1