1,183
社区成员
发帖
与我相关
我的任务
分享
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils,
Classes,
Windows;
type
TRunThread = class(TThread)
protected
procedure Execute(); override;
end;
var
dwCpuCount: Cardinal;
curCpu: Cardinal = 0;
procedure TRunThread.Execute;
var
startTime: Cardinal;
begin
startTime := GetTickCount;
while not Terminated do
begin
if GetTickCount - startTime > 8000 then
begin
Inc(curCpu);
if curCpu > dwCpuCount then
curCpu := 0;
SetThreadAffinityMask(Self.Handle, curCpu);
startTime := GetTickCount;
end;
end;
end;
function getCpuCount: Cardinal;
var
sysinfo: TSystemInfo;
begin
GetSystemInfo(sysinfo);
Result := sysinfo.dwNumberOfProcessors;
end;
begin
dwCpuCount := getCpuCount;
TRunThread.Create(False);
Readln;
end.