我有一个包含多个线程的程序,一个线程将在退出时更改全局,另一个线程将重复轮询全局.对全局变量没有任何保护.该程序在单处理器上运行良好.在双核机器上,它会工作一段时间,然后在Sleep(0)或SuspendThread()上停止.有人能帮我解决这个问题吗?
代码如下:
Thread 1:
do something...
while(1)
{
.....
flag_thread1_running=false;
SuspendThread(GetCurrentThread());
continue;
}
Thread 2
flag_thread1_running=true;
ResumeThread(thread1);
.....do some other work here....
while(flag_thread1_running) Sleep(0);
....
Run Code Online (Sandbox Code Playgroud)