On 24 May 2006 03:43:43 -0700, aditya_min1978@yahoo.com wrote:
Hi All,
i am a new commer software engineer.
i have a confusion. i am mentioning the problem below.
Suppose i have one main UI thread A and now i created one more UI
thread B from A using the following function of A
BOOL A::CreateUIthread()
{
newpointer = Create the another UI thread B from A;
newpointer->Func( 2);
}
Class B: CwinThread
{
int a;
public:
void Func(int data)
{ a = data;}
}
now when i called the function of B using the newpointer from the
function CreateUIthread() then that function will expectue in thread A
or in thread B? The function parameters will be in which thread stack?
It will execute in the thread of the caller, i.e. thread A. The parameters
will be on thread A's stack. It is always true that a function call
executes in the thread of the caller, but it is also true that some
functions will cause another thread to run. For example, SendMessage
directed at a window the calling thread did not create will block until the
thread that created the window calls GetMessage, PeekMessage, WaitMessage,
etc, at which point, the target thread will process the message. (There is
a queue of these pending interthread sent messages separate from what we
think of as the normal message queue.) Only after the target thread has
returned from its window procedure or called ReplyMessage will the sender
thread proceed. It is important to understand this, because most CWnd
functions amount to SendMessage under the hood, and it's usually a mistake
to call SendMessage between threads, due to the danger of indefinite
waiting and outright deadlock in code that wasn't designed for this.
I think it is a mistake to use SendMessage between threads, as to do so is using
apparent from the documentation and therefore subject to change in future versions.
I don't fully understand why anyone would want to do so really as there are much
better ways of interthread communication and synchronization. Sending an