Article View: borland.public.cppbuilder.nativeapi
Article #10259Problem with WaitCommEvent in thread
From: Martin Nijhoff
Date: Tue, 11 May 2004 08:46
Date: Tue, 11 May 2004 08:46
40 lines
2074 bytes
2074 bytes
I wrote a serial communications component, which uses non-overlapped I/O and
creates a second thread to monitor events like the reception of a character,
parity error, etc. Here's the code for the thread's Execute() method:
void __fastcall TCOMThread::Execute()
{
DWORD EvtMask, Errors;
COMSTAT Status;
SetCommMask(COMPort->PortHandle, EV_ERR | EV_RXCHAR | EV_CTS | EV_DSR);
while (!Terminated)
{
WaitCommEvent(COMPort->PortHandle, &EvtMask, NULL);
ClearCommError(COMPort->PortHandle, &Errors, &Status);
if (EvtMask & EV_ERR)
{
// Handle error.
}
// Process other events.
}
}
PortHandle is a private data member of TCOMPort and TCOMThread is defined as
a friend class of TCOMPort.
This code worked fine in Windows 98. In Windows NT and XP, the
WaitCommEvent() call causes not only to suspend the thread, but also to lock
the main application until one of the specified events occurs. The
application appears to hang as soon as it is started, but works 'normal'
when a constant stream of data is received. I dont't understand how a thread
can lock the application that spawned it.
Can anyone tell me what I'm doing wrong?
Regards,
Martin Nijhoff
Technical Details
Message-ID:
<40a092fd$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,4298e6c7d8d30497,start X-Google-Attributes: gid10cc67,public From: "Martin Nijhoff" <dont@mail.me> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Problem with WaitCommEvent in thread Date: Tue, 11 May 2004 10:46:33 +0200 Lines: 43 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 NNTP-Posting-Host: 80.100.129.156 Message-ID: <40a092fd$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1084265213 80.100.129.156 (11 May 2004 01:46:53 -0700) Path: arc1-ca.pugleaf.net!controlnews3.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail