环境是D7
新建一个空程序就在线程里while true do
inc(i);
就这样,CPU就50%了 而同样代码 VC则不会尝试过 加SLEEP(1) 有效果 但因为要捕包 所以不允许有任何 睡眠在线程 create时候 降低优先级 没任何效果请教高手了 谢谢
新建一个空程序就在线程里while true do
inc(i);
就这样,CPU就50%了 而同样代码 VC则不会尝试过 加SLEEP(1) 有效果 但因为要捕包 所以不允许有任何 睡眠在线程 create时候 降低优先级 没任何效果请教高手了 谢谢
tmyThread.Resmue;线程里只有while true do
inc(i);就这样 CPU就50了哦 救命啊 大侠们
begin
Inc(i);
Application.HandleMessage;
end;
begin
Inc(i);
Application.ProcessMessage;
end;
begin
inc(i);
sleep(0);
end;这样可以有效降低CPU占用高么还有 我的捕包是用 winpcap 来 循环捕的,貌似自带没 事件 - -。。
Res
A thread can relinquish the remainder of its time slice by calling this function with a sleep time of zero milliseconds.
如果不允许任何睡眠那你就应该同时不允许其他程序分到任何时间片,那就死机了。
肯定需要sleep的。
CThreadPauseTime = 10;
...
procedure TLeonSuRockeyThread.Execute;
begin
while (not Terminated) do
begin
if FPaused then
begin
Sleep(CThreadPauseTime * 1000);
end;
FTime := (GetTickCount - FStartTime) div 1000;
if FTime >= CThreadPauseTime then
begin
FStartTime := GetTickCount;
Synchronize(DoOnTime);
end;
if (not Terminated) then
Sleep(CThreadPauseTime * 1000);
end;
end;
...结论就是用Slepp能达到我满意的效果(CPU占用 0%),但有一定的小技巧。