Windows threading: _beginthread vs _beginthreadex vs CreateThread C++

后端 未结 17 1525
臣服心动
臣服心动 2020-11-22 17:26

What\'s a better way to start a thread, _beginthread, _beginthreadx or CreateThread?

I\'m trying to determine what are the adv

17条回答
  •  时光说笑
    2020-11-22 17:51

    CreateThread() is Windows API call that is language neutral. It just creates OS object - thread and returns HANDLE to this thread. All windows applications are using this call to create threads. All languages avoids direct API call for obvious reasons: 1. You don't want your code be OS specific 2. You need to do some house keeping before calling API-like: convert parameters and results, allocate temporary storage etc.

    _beginthreadex() is C wrapper around CreateThread() that accounts for C specific. It enables original single threaded C f-ns work in multithreaded environment by allocating thread specific storage.

    If you don't use CRT you cannot avoid a direct call to CreateThread(). If you use CRT, you must use _beginthreadex() or some CRT string f-ns may not work properly prior VC2005.

提交回复
热议问题