Difference between Afxbeginthread and CreateThread
c++, mfc, multithreading
Solution
For MFC programs, use `AfxBeginThread`.
`CreateThread` is raw Win32. It's incompatible with parts of the standard library.
`_beginthread` is part of the C standard library. It adds extra code to handle thread safety for other parts of the standard library that would be unsafe if you used `CreateThread` instead.
`AfxBeginThread` is (obviously enough) part of MFC. Along with the thread safety supported by `_beginthread`, it adds some (if only a few) C++ niceties.
So, you should only use CreateThread if the rest of your program is also pure, raw Win32, with no use of the standard library or MFC. If you're using MFC otherwise, you should normally use `AfxBeginThread` rather than `CreateThread`.
Problem
Is there any drawbacks for using Afxbeginthread. When should we use AfxBeginThread and when should we use CreateThread API.