Skip to content
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

libdispatch threads should call GSUnregisterCurrentThread() on exit #428

Open
triplef opened this issue Aug 2, 2024 · 2 comments
Open
Assignees

Comments

@triplef
Copy link
Member

triplef commented Aug 2, 2024

Threads started by libdispatch currently don’t clean up their NSThread data when the threads exit. This can cause issues e.g. when [[NSThread currentThread] threadDictionary] is used from such threads as this data will never get released.

libdispatch has a _dispatch_install_thread_detach_callback() hook (currently only available on Android) that can be used for this. We currently use a libdispatch patch to make the hook available on all platforms and install a hook to call GSUnregisterCurrentThread() on thread exit in our app.

It would be nice to install the hook callback from libs-base if the hook is available. To start with I’ll open a libdispatch pull request with our patch.

@triplef
Copy link
Member Author

triplef commented Aug 12, 2024

Opened apple/swift-corelibs-libdispatch#841.

@rfm
Copy link
Contributor

rfm commented Aug 17, 2024

This sounds like some sort of bug ... as far as I can see cleanup should take place irrespective of how a thread was started, libdispatch is in no way a special case and I don't see why it should need an extra callback.
The way it is supposed to work is that GS_THREAD_KEY_INIT registers a a function (via pthread_key_create() or FlsAlloc() on windows) to be called when a thread exits, and that function performs the cleanup. This should work irrespective of what code creates the thread.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants