Jump to content
  • Advertisement

Archived

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

kuphryn

MFC Controls and Thread Safety :: MFC

This topic is 5821 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I read an interesting thread at a MSDN newgroup on MFC and thread safety. Its author asks about why a thread causes the process to hang when you pass to the thread points to MFC control objects (CListrCtrl, CEdit, CTreeCtrl, etc). I remember something similar to what the author of thread asks from a application I just finished. I found that you can make changes to MFC controls from threads via pointers to the controls. Everything works well until you call WaitForSingleObject(), or WaitForMultipleObject(), etc. In other words, the process hangs if you call WaitForSingleObject() when the thread is updating an MFC control. Ivan Lalis posted an interesting solution involving MFC controls handles. He writes that one solution is to pass in the worker threads handles to MFC controls instead of pointers.
    
UINT theWorkerThread(LPVOID pParam)
{
   CListCtrl theList;
   theList.attach(handleToRealListbox);
   ...
   theList.detach();
   return 0;
}
    
I would like to know what is the safest solution to this problem? Secondly, in terms of Lalis' solution, do you create and attach, for example, one CListCtrland for the entire life-time of the thread? Thanks, Kuphryn [edited by - kuphryn on December 6, 2002 12:56:36 PM]

Share this post


Link to post
Share on other sites
Advertisement
because mfc handle maps are thread-specific, and aren''t shareable across threads. so you have to use raw handles for interthread communication.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!