官方下载 进程资源管理器 - Windows Sysinternals | Microsoft Docs
查看线程
考虑如下代码
#include <iostream>
#include <vector>
#include <thread>
using namespace std;
long long g_i = 0;
void f1(void)
{
while (true)
{
g_i++;
}
}
void f2(void)
{
while (true)
{
g_i++;
}
}
int main()
{
std::thread t1(f1);
std::thread t2(f2);
t1.join();
t2.join();
std::cout << g_i << std::endl;
return 0;
}
其进程状态如下

main函数主线程
可以看出mainCRTStartup这个线程代表的是main函数所在的主线程。
双击打开会看到:

本文通过一个C++示例程序,展示了如何使用标准库中的`<thread>`来创建和管理线程,并分析了线程的状态及调用栈。同时,通过进程资源管理器工具观察线程执行的具体细节。
最低0.47元/天 解锁文章
1万+

被折叠的 条评论
为什么被折叠?



