Windows threading: _beginthread vs _beginthreadex vs CreateThread C++

后端 未结 17 1493
臣服心动
臣服心动 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:52

    This is the code at the core of _beginthreadex (see crt\src\threadex.c):

        /*
         * Create the new thread using the parameters supplied by the caller.
         */
        if ( (thdl = (uintptr_t)
              CreateThread( (LPSECURITY_ATTRIBUTES)security,
                            stacksize,
                            _threadstartex,
                            (LPVOID)ptd,
                            createflag,
                            (LPDWORD)thrdaddr))
             == (uintptr_t)0 )
        {
                err = GetLastError();
                goto error_return;
        }
    

    The rest of _beginthreadex initializes per-thread data structure for CRT.

    The advantage of using _beginthread* is that your CRT calls from thread will work correctly.

提交回复
热议问题