Fixes for running dedicated built-in mi.Threads #138
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Bugfix
Description
Two of the three commits are simple Thread class fixes (no undefined default priorities, give back GIL while waiting for Thread methods to resume).
The third commit addresses a rather ugly conflict between
mi.Thread
-derived andThreadNotifier
WorkerThread
instances. I am sure you are well aware of the somewhat unfortunate layering of threading functionality at this point. The provided fix addresses too possible implementations of C++thread_local
storage:ThreadNotifier
initialization on thread start (not actually happening on my system), in which case the fix now replaces theWorkerThread
instance by the instance of the dispatchedmi.Thread
-derived object with proper reference counting and destruction.ThreadNotifier
, in which case the fix prevents correctmi.Thread
-derived objects to accidentally be replaced with anonymousWorkerThread
instances that easily lead to crashes when lacking the right ThreadEnvironment settings.Testing
Minimal repro (Ubuntu 20.04 LTS, Python 3.8):
Checklist:
Please make sure to complete this checklist before requesting a review.
cuda_*
andllvm_*
variants. If you can't test this, please leave below[ ] I have made corresponding changes to the documentation[ ] I have added tests that prove my fix is effective or that my feature works