Difference between Afxbeginthread and CreateThread

前端 未结 2 1378
遥遥无期
遥遥无期 2020-12-30 15:34

Is there any drawbacks for using Afxbeginthread. When should we use AfxBeginThread and when should we use CreateThread API.

2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-30 16:31

    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.

提交回复
热议问题