gpt4 book ai didi

linux - 什么时候在 std::thread 上调用 native_handle() 是安全的?

转载 作者:太空宇宙 更新时间:2023-11-04 12:47:33 25 4
gpt4 key购买 nike

我正在创建一个 std::thread,然后尝试获取 native 句柄(它将用于设置线程名称)。

auto mThread = std::thread(threadActionFcn);

#ifdef DEFINITELY_LINUX_PTHREADS
auto handle = mThread.native_handle();
pthread_setname_np(handle, name);
#endif

我能否保证 mThread 在构造函数执行后初始化,或者这是竞争条件?

最佳答案

当然,您可以对创建的 std::thread 对象进行任何调用。其他一切都将是一个巨大的陷阱。

关于linux - 什么时候在 std::thread 上调用 native_handle() 是安全的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38260552/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com