Re: Is it safe to send one thread's stack buffer pointer to another th
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:ugZ20n04HHA.4476@TK2MSFTNGP06.phx.gbl...
Ben Voigt [C++ MVP] <rbv@nospam.nospam> wrote:
"Igor Tandetnik" <itandetnik@mvps.org> wrote in message
news:ue4udKo4HHA.3400@TK2MSFTNGP03.phx.gbl...
It is OK to pass a pointer into a thread's stack to another thread -
as long as you can be sure the stack frame is alive as long as the
second thread refers to it. That is, the main thread must not return
from the function call before the second thread does. At which
point, it's not clear why you would want to switch to another thread
in the first place.
COM marshalling would be a good reason to do so.
COM marshalling doesn't just pass a pointer to the stack frame over to the
other thread. It actually serializes all the parameters into a binary
stream and sends that over. On the other end, the stream is deserialized
and a copy of the stack frame is recreated.
I know that's true for inter-process DCOM, but does DCOM marshalling of an
in-process component do the same?
In fact, pointers to stack variables are commonly passed to another
thread using the SendMessage function, which does indeed block until
the other thread indicates it is done using the parameters by
returning from the wndproc.
Yes, I'll grant you that.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925