Need Thread Advice
- From: "mike" <nospamplease.com>
- Date: Wed, 29 Mar 2006 10:36:11 -0500
I have an application that utilizes 2 threads for communications; 1 for
receive and 1 for transmit. The threads are derived classes of CWinThread.
The code is written so that when a button is clicked, I open a com port and
immediately send data out the port. There was a timing problem in that when
the port was opened, the threads were not running at the time that the
transmit operation was begun. To overcome this, I added a Ready flag in the
threads and when I open the port, I check this flag to make sure the thread
is running before exiting the open com function.
/* pseudo code */
OpenCom()
{
/*... open comm stuff */
pthread = CreateThread(......);
pthread->ResumeThread();
while ( !pthread->Ready ) ;
}
The debug code worked ok, but the release code hung in the while() loop. I
realized I had to free up time for the thread so I changed it to
while ( !pthread->Ready ) Sleep(5);
This seems to work. My question is, is there a better way to accomplish
this.
Thanks
.
- Follow-Ups:
- Re: Need Thread Advice
- From: Doug Harrison [MVP]
- Re: Need Thread Advice
- From: Scott McPhillips [MVP]
- Re: Need Thread Advice
- Prev by Date: Re: Bitmap resize on same DC
- Next by Date: Re: Bitmap resize on same DC
- Previous by thread: Re: Equivalen DoEvents method
- Next by thread: Re: Need Thread Advice
- Index(es):