J R - 2012-03-09

Hi,
there's in evil race in TComThread.Create (current svn), which made my app fail to initialize the serial port.
TComThread.Create calls

inherited Create(false);

which may immediately (or at least rather soon) start TComThread.Execute. Such it may happen (and in fact happened to me) that

WaitCommEvent(FComPort.Handle, Mask, @Overlapped);

in TComThread.Execute is executed before or in parallel to

SetCommMask(FComPort.Handle, EventsToInt(FComPort.Events));

in TComThread.Create and this will fail or wrongly initialize the serial port.
On solution would be to put SetCommMask into Execute, but then it could be that Execute accesses the event handles that are created in Create too. So the correct and simple solution is to change Create:

inherited Create(true);

and later on call Resume (I'm using BCB5 still). However, code like this is already there, but commented. Why?

{$IFDEF Unicode}Start;  {$ELSE}  Resume;  {$ENDIF}

Regards