-
-
Notifications
You must be signed in to change notification settings - Fork 7k
windows: replace _beginthreadex() with CreateThread()
#18451
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Thanks, updated the PR message to not say deprecated. I don't know if the preference for
Do you see a way to perhaps drop that call from the curl tool code? |
Since
As far as I can see, it seems to only be called if the main thread fails to connect to a socket created by the console thread, would it not be possible to make the console thread connect to main thread instead and then have the thread creation be last in the code there so that there'd be no need to close stuff there? The socket there could probably be replaced with |
209d433 to
9f88369
Compare
Pushed commits to switch to CreateThread(), let's see what CI has to say.
Sounds sensible. Would you want to make a PR? |
I'm still working on the PR I mentioned earlier in the Windows XP PR (it's a Win32 async DNS resolver to replace the threaded one), I'd rather prefer to finish that before doing other stuff (doing it partially for the project I work on since we decided to abandon c-ares due to it being full of bugs and using the proper async APIs should be better than the threading hacks). |
Got it, no worries! /off The Win32 async DNS support reminded me of this commit (and those linked from the message), in case its useful reference: eb8ad66 #14794 |
I guess for classic MinGW. It explicitly said to use |
|
@MarcelRaad Hm, I wonder if this may apply to non-old-mingw too. That https://learn.microsoft.com/en-us/cpp/parallel/multithreading-with-c-and-win32?view=msvc-170 |
I assume this only applies to the legacy CRT then, not the new UCRT. |
So I guess if any one of the supported Windows targets still use or support non-UCRT AFAIK VS2015 is the first version with UCRT support. We still stupport VS2008, soon |
|
If the CRT can't initialize a thread created by CreateThread it terminates the thread, that is what it means by low memory conditions, it needs some memory to initialize the CRT when it is called since it isn't initialized beforehand since beginthreadex wasn't used. I think Windows probably does this anyway IIRC. I've worked in low memory and resource conditions and Windows will just kill things but (usually) the OS keeps running. Who's to say if beginthreadex could really do anything if you're out of memory. When you're out of memory all bets are off. Using CreateThread has one minor advantage which is it's easier to work when debugging because the start address will show as the function that was threaded and not the crt initialization wrapper. |
This reverts commit cb8cd80.
97fe189 to
8246a0a
Compare
CreateThread()_beginthreadex() with CreateThread()
Follow-up to 1c49f2f curl#18451
Both WinCE and Windows use CreateThread() now, so the use of `GetLastError()` works for both. Follow-up to 03448f4 curl#18998 Follow-up to 1c49f2f curl#18451 Follow-up to af02162 curl#1589
Both WinCE and Windows use `CreateThread()` now, so the use of `GetLastError()` works for both. Follow-up to 03448f4 curl#18998 Follow-up to 1c49f2f curl#18451 Follow-up to af02162 curl#1589 Closes curl#19015
Replace
_beginthreadex()C runtime calls with native win32 APICreateThread(). The latter was already used insrc/tool_doswin.cand in UWP and Windows CE builds before this patch. After this patch
all Windows flavors use it. To drop PP logic and simplify code.
While working on this it turned out that
src/tool_doswin.ccallsTerminateThread(), which isn't recommended by the documentation,except for "the most extreme cases". This patch makes no attempt
to change that code.
Ref: 9a26633 #17572
Ref: https://learn.microsoft.com/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminatethread
Also:
WaitForSingleObjectEx()on all desktop Windows.Ref: 4be80d5
Ref: https://sourceforge.net/p/curl/feature-requests/82/
Ref: https://learn.microsoft.com/windows/win32/api/synchapi/nf-synchapi-waitforsingleobjectex
support.
Assisted-by: Jay Satiro
Assisted-by: Marcel Raad
Assisted-by: Michał Petryka
Follow-up to 3802910 #11625
w/o sp https://github.com/curl/curl/pull/18451/files?w=1