I have written a test program to bind a thread on a CPU.Here is my test code:
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
DWORD WINAPI ThreadFunc(LPVOID pM) {
while(1) {
printf("Doesn't work anymore"); //If i add this printf function,the setthreadaffinitymask seems doesn't work anymore.Which u can see from two pictures i post.
}
}
int main()
{
HANDLE h;
DWORD_PTR RetFlag;
h = CreateThread(NULL, 0, ThreadFunc, NULL, 0, NULL);
if((RetFlag = SetThreadAffinityMask(h, 0x08)) == 0)
printf("SetThreadAffinityMask fails\n");
WaitForSingleObject(h, INFINITE);
return 0;
}
And of course, the right result should be like pic one.But what's going on if i add printf() function in the thread function?Is there any trick i don't know?Thanks...