X
xjf
Unregistered / Unconfirmed
GUEST, unregistred user!
Comm32控件采用了多线程技术,定义了ReadThread 和 WriteTHread
本人在调试程序时发现线程冲突,并造成Access violation错误.
具体如下:
在Startcom函数中,
// Create the Read thread.
try
ReadThread := TReadThread.Create( True {suspended} );
except
LogDebugLastError( GetLastError, 'Unable to create Read thread' );
raise ECommsError.Create( 'Unable to create Read thread' );
end;
ReadThread.hCommFile := hCommFile;
ReadThread.hCloseEvent := hCloseEvent;
ReadThread.hComm32Window := FHWnd;
ReadThread.Resume;
ReadThread.Priority := tpHighest;
// Create the Write thread.
try
WriteThread := TWriteThread.Create( True {suspended} );
except
LogDebugLastError( GetLastError, 'Unable to create Write thread' );
raise ECommsError.Create( 'Unable to create Write thread' );
end;
WriteThread.hCommFile := hCommFile;
WriteThread.hCloseEvent := hCloseEvent;
WriteThread.hComm32Window := FHWnd;
WriteThread.Resume;
当写线程Resume,就发生错误.此时读线程正在进行读操作.
请问如何修正?
本人在调试程序时发现线程冲突,并造成Access violation错误.
具体如下:
在Startcom函数中,
// Create the Read thread.
try
ReadThread := TReadThread.Create( True {suspended} );
except
LogDebugLastError( GetLastError, 'Unable to create Read thread' );
raise ECommsError.Create( 'Unable to create Read thread' );
end;
ReadThread.hCommFile := hCommFile;
ReadThread.hCloseEvent := hCloseEvent;
ReadThread.hComm32Window := FHWnd;
ReadThread.Resume;
ReadThread.Priority := tpHighest;
// Create the Write thread.
try
WriteThread := TWriteThread.Create( True {suspended} );
except
LogDebugLastError( GetLastError, 'Unable to create Write thread' );
raise ECommsError.Create( 'Unable to create Write thread' );
end;
WriteThread.hCommFile := hCommFile;
WriteThread.hCloseEvent := hCloseEvent;
WriteThread.hComm32Window := FHWnd;
WriteThread.Resume;
当写线程Resume,就发生错误.此时读线程正在进行读操作.
请问如何修正?