Archived

This topic is now archived and is closed to further replies.

Nick2048

Window message threads

Recommended Posts

Has anyone had exerpience using window message threads in a game? Is it avisable, or is there some problem with them that I don''t see?

Share this post


Link to post
Share on other sites
No, I mean using Window message threads as a means to pass information from one thread to another. Say I have one subsystem in one thread which generates events that are sent to another subsystem in another thread.

Share this post


Link to post
Share on other sites
I have no idea what you mean by "window message threads".

If you have multiple threads with a message pump in each one (i.e. they call GetMessage/PeekMessage/etc) then you can use PostThreadMessage to send a message from one to another. It works fine.

There are a billion other ways to do interthread communication also.

-Mike

Share this post


Link to post
Share on other sites
Using windows message threads I take it means starting a thread that has its own separate message queue. In MFC-speak, it''s a UI thread instead of a worker thread. I can''t say whether it''s good or bad--it has its uses, and it really depends on what you''re trying to do. If messages are a comfortable way for you to do inter-thread communication, and you like the thread paradigm of using ::WaitMessage in the main loop, go for it.

Share this post


Link to post
Share on other sites
The only problem with it, is that you have to wait for the OS to route the message - if that doesn''t matter it''ll work fine.

Alternatives are events and semaphores and access to the same data structures protected with critical sections. You can pass a thread a context pointer, so you can run a thread within the context of a class to give it access to data, if you want to.

Share this post


Link to post
Share on other sites