Re: Reading Serial Port
 
"clinisbut" <clinisbut@gmail.com> wrote in message 
news:fd46315b-cfa9-4ac7-95e6-45a9690c1d6e@d21g2000prf.googlegroups.com...
OK, so it looks like pMySerial has another worker thread (pReaderThread)
that needs to be ended when pMySerial thread is ending?  That's what the
above 2 lines say.
Yes, Inside my MySerial UI thread I have a worker thread
(ReaderThread ). I explained it some post ago.
   pReaderThread = AfxBeginThread( ReaderThread, this,
THREAD_PRIORITY_NORMAL );
This is how I create it.
Set a breakpoint in pReaderThread that is waiting for ShutdownEvent. 
Does
it get it?  Does it properly exit the thread function when it does get 
it?
I set a breakpoint where ReaderThread gets ShutdownEvent and it
reaches ok.
When the thread function is exited, WFSO returns, and
pReaderThread->m_hThread is nomore.  You should close its handle:
     CloseHandle( pReaderThread->m_hThread);
Sorry, I look better for the problem and I found that actually it pass
ok through that WFSO( pReaderThread->m_hThread, INFINITE ). That was
another problem (not related) and all code is executed, but still with
that memory leak:
MySerial.cpp(21) : {120} client block at 0x00432410, subtype 0, 224
bytes long. a MySerial object at $00432410, 224 bytes long
That points to
 IMPLEMENT_DYNCREATE(MySerial, CWinThread)
in my header.
Also, the WM_MY_SERIAL_CLOSE handler does not terminate the pMySerial
thread!  You need to add this after pReaderThread has successfully
terminated:
    PostThreadMessage (GetCurrentThreadId(), WM_QUIT, 0, 0);
Doesn't do this the PostQuitMessage(0); I already have? (You can see
it some post 5 post above)
I don't know, like I said, I haven't followed this conversation very 
carefully.  But the only PostQuitMessage() call I see is in a function 
called MySerial::closePort() which I didn't think was the same thing, and I 
don't know what that function executes.
Anyway, now you say the problem with WFSO not returning has been resolved. 
And still the only remaining problem is a memory leak of MySerial.  If the 
AutoDelete member is set to FALSE, you need to delete it prior to your 
program exiting.  Set a breakpoint on that code and see if it executes.  If 
AutoDelete is instead TRUE, MySerial should be deleted when the WM_QUIT 
message is processed.  Set a breakpoint in MySerial::~MySerial to be sure.
-- David