我现在写一个程序,在单核CPU的机器上运行正常,在双核CPU的机器上运行,程序会死,而如果在双核cpu机器上关闭一个核心后,就能正常运行
请问,如何用delphi来判断当前机器是否是双核CPU,如果是双核,怎么用代码来关闭其中一个核心?

解决方案 »

  1.   

    笑死我了,程序死掉不改程序,居然会想到关CPU核心
    不过这个问题值得关注。判断双核可以用WMI,怎么关闭就不知道了
      

  2.   

    程序運行不了跟CPU有沒有關系呢?
    按照樓主的實踐,是有關系的。占個位置學習下
      

  3.   

    程序已经修改好了没问题了
    并且关CPU的也搞定了,哈哈
      

  4.   

    SetProcessAffinityMask 函数
    The SetProcessAffinityMask function sets a processor affinity mask for the threads of the specified process.  
    定义 
    BOOL SetProcessAffinityMask(HANDLE hProcess, DWORD_PTR dwProcessAffinityMask);  
    参数 
      hProcess 
        [in] Handle to the process whose affinity mask is to be set. This handle must have the PROCESS_SET_INFORMATION access right. For more information, see Process Security and Access Rights. 
      dwProcessAffinityMask 
        [in] Affinity mask for the threads of the process. 
    返回值 
      If the function succeeds, the return value is nonzero.If the function fails, the return value is zero. To get extended error information, call GetLastError. 
    说明 
      A process affinity mask is a bit vector in which each bit represents the processor on which the threads of the process are allowed to run.The value of the process affinity mask must be a proper subset of the system affinity mask values obtained by the GetProcessAffinityMask function.Do not call SetProcessAffinityMask in a DLL that may be called by processes other than your own.Process affinity is inherited by any child process or newly instantiated local process. 
    系统要求 
      Client: Requires Windows XP, Windows 2000 Professional, or Windows NT Workstation 4.0.
    Server: Requires Windows Server 2003, Windows 2000 Server, or Windows NT Server 4.0.
    Header: Declared in Winbase.h; include Windows.h.
    Library: Link to Kernel32.lib.
    DLL: Requires Kernel32.dll. 
      

  5.   

    SetProcessAffinityMask(GetCurrentProcess(), 0x00000001);治标不治本,可以肯定的是你的多线程程序肯定有缺陷,多核只是让崩溃变的更容易了而已
      

  6.   

    哦,Delphi应该是SetProcessAffinityMask(GetCurrentProcess(), $00000001);
      

  7.   

    多线程的问题是找到了,大量的操作COM口导致程序崩溃,是一个DLL的问题
    修改了DLL就搞定了,顺便也找到这个函数了