Archived

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

kuphryn

Multithreading :: MFC

Recommended Posts

kuphryn    210
Hi. In an MFC project, is better to implement multithreadingusing AfxBeginThread() or a normal create-thread function such as _beginthread() and CreateThread()? I remember Jeff Prosise recommending AfxBeginThread() for MFC. I would like to get more inputs. Thanks, Kuphryn

Share this post


Link to post
Share on other sites
Solo    142
From his book:

"AfxBeginThread isn''t merely a wrapper around the Win32 ::CreateThread function; in addition to launching a thread, it initalizes internal state information used by the framework, performs sanity checks at various points during the thread creation process, and takes steps to ensure that functions in the C run-time library are accessed in a thread-safe manner." - Jeff Prosise "Programming Windows with MFC" 2nd edition

Pretty important stuff. _beginthread(), or better yet _beginthreadex(), should work if the thread isn''t going to run any MFC code. Just remember that they will skip the "initalizes internal state information" part.

You''d do well to stay away from CreateThread(). It doesn''t prepare the C run-time library.

Share this post


Link to post
Share on other sites
kuphryn    210
Okay. Thanks.

Yeah, I know a little about CreateThread and its problems with C run-time. Jeffrey Richter dedicated a section in his Windows programming book about that issue.

Kuphryn

Share this post


Link to post
Share on other sites