为何我设置了线程优先级没有起到作用?代码如下:
int main(int argc, char* argv[])
{
DWORD dwThreadID;
HANDLE h[2]; h[0]=::CreateThread(NULL,0,ThreadIdle,NULL,CREATE_SUSPENDED,&dwThreadID);
::SetThreadPriority(h[0],THREAD_PRIORITY_IDLE);
::ResumeThread(h[0]);

h[1]=::CreateThread(NULL,0,ThreadNormal,NULL,0,&dwThreadID);

::WaitForMultipleObjects(2,h,TRUE,INFINITE); ::CloseHandle(h[0]);
::CloseHandle(h[1]); return 0;
}
运行后,发现结果如下
两个本该不同优先级的线程居然交互运行了,和没改变优先级一样?WHY??
求高手指导,不胜感激啊?我是XP系统

解决方案 »

  1.   

    http://hi.baidu.com/aidilijie/blog/item/328f1a829817bda60df4d204.html
      

  2.   

    不好意思 ,图没贴好,图上显示的是先Idle,然后是Normal,两个线程就这样交互运行了,难道不是Normal先运行完,Idle才可以占用CPU的吗?谢谢大家的回复,图如下:
      

  3.   

    搞不定图片 ,大概就是这个意思,描述的比较清楚了。下面是图的内容
    Idle thread is running!
    Idle thread is running!
    Normal thread is running!
    Idle thread is running!
    Normal thread is running!
    Idle thread is running!
    Normal thread is running!
    Normal thread is running!
    Idle thread is running!...
      

  4.   

    入口函数如下:
    DWORD WINAPI ThreadIdle(LPVOID lpParam)
    {
    int i=0;
    while (i++<10)
    {
    printf("Idle thread is running!\n");

    }
    return 0;
    }DWORD WINAPI ThreadNormal(LPVOID lpParam)
    {
    int i=0;
    while (i++<10)
    {
    printf("Normal thread is running!\n");

    }
    return 0;
    }
      

  5.   

    如果你是双核cpu当然可以同时运行,如果ThreadNormal中有阻塞的工作(printf很可能有等待),Idle也会运行