Skip to content

Use GetThreadId instead of Storing Handles Directly #2440

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

Merged
merged 1 commit into from
Jul 31, 2019

Conversation

gmittert
Copy link
Contributor

CoreFoundation keeps a Dictionary of threads to their runloops. On
Windows, it previously used the threads' Handle as keys into the
dictionary. However, this doesn't work, as if you are attempting to look
up or set the current thread's RunLoop using GetCurrentThread.
GetCurrentThread returns a psuedo handle (FFFFFFFE) rather than a real
handle to a thread which causes it to index incorrectly into the
dictionary.

This was causing the creation of multiple runloops per thread and then
causing dispatch queues not to be pumped leaving blocks to never be run.

The fix here is to use the thread id instead of a handle which is unique
on the system until the thread terminates.

CoreFoundation keeps a Dictionary of threads to their runloops. On
Windows, it previously used the threads' Handle as keys into the
dictionary. However, this doesn't work, as if you are attempting to look
up or set the current thread's RunLoop using GetCurrentThread.
GetCurrentThread returns a psuedo handle (FFFFFFFE) rather than a real
handle to a thread which causes it to index incorrectly into the
dictionary.

This was causing the creation of multiple runloops per thread and then
causing dispatch queues not to be pumped leaving blocks to never be run.

The fix here is to use the thread id instead of a handle which is unique
on the system until the thread terminates.
@gmittert
Copy link
Contributor Author

cc @compnerd

@gmittert
Copy link
Contributor Author

@swift-ci please test linux

Copy link
Member

@compnerd compnerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😒

@gmittert gmittert merged commit 2a4653b into swiftlang:master Jul 31, 2019
@gmittert gmittert deleted the PsuedoGetMeAThread branch July 31, 2019 06:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants