WINS程序设计关于线程的问题,有人懂吗?
线程优先级的问题,谁帮帮我..谢谢..这个程序结果.两个值为什么会不一样呢??
#include<stdio.h>
#include<windows.h>
#include<process.h>
DWORD g1=0;
DWORD g2=0;
BOOL gb=TRUE;
DWORD WINAPI ThreadFunc(LPVOID ipParam);
int main(){
DWORD u;
HANDLE h[2];
h[0]=::CreateThread(NULL,0,ThreadFunc,NULL,CREATE_SUSPENDED,&u);
::SetThreadPriority(h[0],THREAD_PRIORITY_IDLE);
::ResumeThread(h[0]);
h[1]=::CreateThread(NULL,0,ThreadFunc,NULL,0,&u);
Sleep(1000);
gb=FALSE;
::WaitForMultipleObjects(2,h,TRUE,INFINITE);
::CloseHandle(h[0]);
::CloseHandle(h[1]);
printf("终值:%d,%d\n",g1,g2);
return(0);
}
DWORD WINAPI ThreadFunc(LPVOID ipParam){
while(gb){
g1++;
g2++;
}
printf("%d,%d\n",g1,g2);
return(0);
}