提问者:小点点

什么是C++20中的Std::JThread?


  1. 它比std::thread有什么优势?
  2. 是否不推荐使用现有的std::thread

共1个答案

匿名用户

std::jthread类似于std::thread,只是没有愚蠢的。 请参阅,如果您事先没有连接或手动分离程序,std::thread的析构函数将终止该程序。 这导致了成吨的虫子,因为人们预计它会加入破坏。

jthread修复了这个问题; 默认情况下,它在销毁时连接(因此命名为:“连接线程”)。 它还支持请求线程停止执行的机制,尽管没有强制执行(也就是:不能使另一个线程停止执行)。

目前,没有计划弃用std::thread

相关问题


MySQL Query : SELECT * FROM v9_ask_question WHERE 1=1 AND question regexp '(c++20|中|std|jthread)' ORDER BY qid DESC LIMIT 20
MySQL Error : Got error 'repetition-operator operand invalid' from regexp
MySQL Errno : 1139
Message : Got error 'repetition-operator operand invalid' from regexp
Need Help?