S
shameboy
Unregistered / Unconfirmed
GUEST, unregistred user!
最近我在做一多线程操作串口的系统.我分两个线程HThreadA和HThreadB
工作的时候HThreadB优先级要高于HThreadA.
程序启动我创了一个事件EventA := CreateEvent(nil, True, False, 'MyEvent');
HThreadA先运行
function ThreadA_SendForRead(p: pointer): Longint;
stdcall;
var
ObjRtn: Integer;
begin
Application.ProcessMessages;
sleep(100);
SetEvent(EventA);
ObjRtn := WaitForSingleObject(EventA, 10000);
while truedo
begin
SendData(AllDevice_CommandList[Server_Form.Tag]);
Server_Form.Tag := Server_Form.Tag + 1;
ObjRtn := WaitForSingleObject(EventA, 10000);
sleep(1);
end;
end;
HThreadB后运行,但优先级更高
function ThreadA_WriterData(p: pointer): Longint;
stdcall;
begin
Application.ProcessMessages;
sleep(100);
ResetEvent(EventA);
while aaado
...........
setEvent(EventA);
我是这样做线程同异步的.但是发现有时线程A发生死锁.谁有更好的办法,出出点子.
工作的时候HThreadB优先级要高于HThreadA.
程序启动我创了一个事件EventA := CreateEvent(nil, True, False, 'MyEvent');
HThreadA先运行
function ThreadA_SendForRead(p: pointer): Longint;
stdcall;
var
ObjRtn: Integer;
begin
Application.ProcessMessages;
sleep(100);
SetEvent(EventA);
ObjRtn := WaitForSingleObject(EventA, 10000);
while truedo
begin
SendData(AllDevice_CommandList[Server_Form.Tag]);
Server_Form.Tag := Server_Form.Tag + 1;
ObjRtn := WaitForSingleObject(EventA, 10000);
sleep(1);
end;
end;
HThreadB后运行,但优先级更高
function ThreadA_WriterData(p: pointer): Longint;
stdcall;
begin
Application.ProcessMessages;
sleep(100);
ResetEvent(EventA);
while aaado
...........
setEvent(EventA);
我是这样做线程同异步的.但是发现有时线程A发生死锁.谁有更好的办法,出出点子.