Problem understanding MSDN documentation on _beginthreadex and _endthreadex

I read the documentation about _beginthreadexand _endthreadex, but there are a few things that I do not understand.

Note that the documentation continues to document "advanced" and normal functions at the same time, but I do not use _beginthreadand _endthread; only their extended versions.


You can call _endthread or _endthreadex explicitly to terminate the thread; however, _endthread or _endthreadex is called automatically when the thread returns from the procedure passed as a parameter. Terminating a thread with an endthread or _endthreadex call helps ensure proper recovery of resources allocated to the thread.

  • If _endthreadexcalled automatically, what’s called a call, does it help ensure a “proper recovery of resources”? It doesn't matter if I call it or not, or does it?

_endthread automatically closes the thread descriptor (whereas _endthreadex does not). Therefore, when using _beginthread and _endthread, explicitly do not close the thread descriptor by calling the Win32 CloseHandle API.

  • If it _endthreadex doesn't close the handle , why shouldn't I close it with CloseHandle?
  • All my flows only voluntarily cease, returning from their main function and never cease. According to the documentation, when this happens, it is _endthreadexcalled automatically.

    . , , , , ? - ? , ?

+3
1

_endthreadex , , " "? , , ?

, , .

_endthreadex , CloseHandle?

_endthreadex CloseHandle. , _endthread (, , CloseHandle ).

, . , _endthreadex .

, , . ( WaitForSingleObject), . , . , , .

+5

Source: https://habr.com/ru/post/1769918/


All Articles