c++ thread id

创建日期: 2024-05-31 14:35 | 作者: 风波 | 浏览次数: 15 | 分类: C++

来源:https://stackoverflow.com/questions/7432100/how-to-get-integer-thread-id-in-c11

std::hash<std::thread::id>{}(std::this_thread::get_id())

printf("%lu", std::hash<std::thread::id>{}(std::this_thread::get_id()))

int id = 0;
for(auto& work_item : all_work) {
    std::async(std::launch::async, [id,&work_item]{ work_item(id); });
    ++id;
}

std::stringstream ss;
ss << std::this_thread::get_id();
uint64_t id = std::stoull(ss.str());
15 浏览
12 爬虫
0 评论