我在线程中做的事情是每隔60毫秒往串口发送一个数据
所以我在Execute里面写
procedure TSendThread.Execute;
begin
while not Terminated do
begin
SendCommandBuffer; //这是自己写的函数,往串口发数据用的
sleep(60);
end;
end;
然后CPU就100% 了,我的程序里面只有这一个子线程,优先级是tpLower,那么是不是这个Sleep的问题呢?怎样做到每隔一定的时间做一件事情啊,Timer好像在线程里面也不大好用哦。。
所以我在Execute里面写
procedure TSendThread.Execute;
begin
while not Terminated do
begin
SendCommandBuffer; //这是自己写的函数,往串口发数据用的
sleep(60);
end;
end;
然后CPU就100% 了,我的程序里面只有这一个子线程,优先级是tpLower,那么是不是这个Sleep的问题呢?怎样做到每隔一定的时间做一件事情啊,Timer好像在线程里面也不大好用哦。。
var lStart: DWord;
begin
lStart := GetTickCount;
while GetTickCount - lStart <= lMilliSeconds do
Application.ProcessMessages;
end;
持有了一个锁(比如TMultiReadExclusiveWriteSynchronizer,或者TRTLCriticalSection),
没有释放(EndRead,EndWrite, LeaveCriticalSection之类)
而主程序当前执行代码正请求这个锁...
英雄所见略同