Re: thread - structure
On Tue, 20 Jun 2006 19:33:32 -0500, "cdg" <anyone@anywhere.com> wrote:
Thanks for your post.
And there was just one other issue I thought I would ask about. Do the
rules of class members access apply in the new thread, so that function
calls to other functions in the same class work normally. Since the worker
thread and the main thread are all in the same class. However, these
functions will not be used in the main thread.
Functions are not associated with threads. That is, any thread can call any
function, and the function executes in the context of the thread that
called it. That's true for all normal functions. A very notable exception
is SendMessage, and it's special because:
1. Windows allows only the thread that created a window to process messages
for that thread. This means interthread SendMessage is synchronous, and it
involves blocking the calling thread until the target thread has returned
from its window procedure or called ReplyMessage. Because the calling
thread cannot proceed, it's possible it will halt indefinitely or even
deadlock with the target thread; careful design of the sender/target
threads is necessary to avoid these problems. However, the calling thread
will process sent messages while in this weird state, which allows windows
to communicate back and forth, as parent and child windows often do, so the
problem is mitigated in many cases.
2. Many CWnd and Windows API functions use SendMessage under the hood, so
to play it safe, define a custom interface based on user-defined messages
and post them to your window using PostMessage.
--
Doug Harrison
Visual C++ MVP