difference between CreateThread & AfxBeginThread
-
I wanted to know what is difference between CreateThread & AfxBeginThread while creating thread? Thanks in advance Nikesh
-
I wanted to know what is difference between CreateThread & AfxBeginThread while creating thread? Thanks in advance Nikesh
When you're using MFC for developing applications, you should use
AfxBeginThread()
due to internal things in the framework that need to be set up correctly.::CreateThread()
is the Platform SDK version version when building applications with C++ without MFC support. At last a little hint, pasted from MSDN: A thread that uses functions from the C run-time libraries should use the beginthread and endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
When you're using MFC for developing applications, you should use
AfxBeginThread()
due to internal things in the framework that need to be set up correctly.::CreateThread()
is the Platform SDK version version when building applications with C++ without MFC support. At last a little hint, pasted from MSDN: A thread that uses functions from the C run-time libraries should use the beginthread and endthread C run-time functions for thread management rather than CreateThread and ExitThread. Failure to do so results in small memory leaks when ExitThread is called."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknownRoger Stoltz wrote:
should use the beginthread and endthread
You should use beginthreadex() as it gives you more control, and endthreadex() as endthread() is fundamentally flawed.
modified on Tuesday, December 9, 2008 4:45 AM
-
Roger Stoltz wrote:
should use the beginthread and endthread
You should use beginthreadex() as it gives you more control, and endthreadex() as endthread() is fundamentally flawed.
modified on Tuesday, December 9, 2008 4:45 AM
Defenestration wrote:
You should use beginthreadex() as it gives you more control, and endthreadex() as endthread() is fundamentally flawed.
As I wrote, this was a quote from MSDN as a hint when using Kernel32.dll from other languages than C/C++ and a different calling convention is used. Regarding the use of any of the functions for "ending" a thread, neither of them should be used. You should simply return from the thread controlling function and if that turns out to be a problem, the design should be corrected. Regarding
beginthreadex()
, you may use it unless you're building an MFC application. The only correct option is to useAfxBeginThread()
when building with MFC support. This is not a matter of opinion."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknown -
Defenestration wrote:
You should use beginthreadex() as it gives you more control, and endthreadex() as endthread() is fundamentally flawed.
As I wrote, this was a quote from MSDN as a hint when using Kernel32.dll from other languages than C/C++ and a different calling convention is used. Regarding the use of any of the functions for "ending" a thread, neither of them should be used. You should simply return from the thread controlling function and if that turns out to be a problem, the design should be corrected. Regarding
beginthreadex()
, you may use it unless you're building an MFC application. The only correct option is to useAfxBeginThread()
when building with MFC support. This is not a matter of opinion."It's supposed to be hard, otherwise anybody could do it!" - selfquote
"High speed never compensates for wrong direction!" - unknownRoger Stoltz wrote:
Regarding the use of any of the functions for "ending" a thread, neither of them should be used. You should simply return from the thread controlling function
Indeed, and the only bulletproof method for knowing when a thread has finished, is to Wait...() on the thread handle. :)