Re: Passing an address as LPARAM
<pbruyant@yahoo.com> wrote in message
news:db9e468e-1975-4422-a125-61a3a895b2fa@z7g2000vbh.googlegroups.com...
On 14 mai, 22:21, "Victor" <nijegorodov.otp...@freenet.de> wrote:
Not a good approach! It could cause a dead lock.
Read this Joe's essay to learn how to make it a right
way:http://www.flounder.com/workerthreads.htm
Victor
Thanks for your remark, but could you be more explicit please? Where
could be the deadlock ?
TXS
Phil
SendMessage is only half of a recipe for a deadlock. When SendMessage is
used to send a message to a window created in another thread the call blocks
(suspending the calling thread) until the destination thread processes the
message. If the destination thread is suspended (for example, if it is
doing WaitForSingleObject on the thread handle) then it could wait forever,
and thus both the sending and receiving thread become deadlocked, each
waiting for the other to do something.
If the sending thread uses PostMessage then such a deadlock cannot happen,
since PostMessage puts the message in the queue and then returns, not
waiting for the destination thread to do anything.
--
Scott McPhillips [VC++ MVP]