-
-
Notifications
You must be signed in to change notification settings - Fork 21.8k
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
Modernize Thread #45315
Modernize Thread #45315
Conversation
8c7f49a
to
9b10382
Compare
3ce1a07
to
d269cce
Compare
Thread::~Thread() { | ||
if (id != 0) { | ||
#ifdef DEBUG_ENABLED | ||
WARN_PRINT("A Thread object has been destroyed without wait_to_finish() having been called on it. Please do so to ensure correct cleanup of the thread."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still really needed? Documentation states resources are freed once the thread exits: https://en.cppreference.com/w/cpp/thread/thread/detach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My concern is that the code running on the thread, if left to run wildly, may access something that is already released on or in a wrong state.
Maybe in practice that's unlikely, but I thought it was a good idea to just warn against fire-and-forget, so joining the thread is the de facto standard practice, which can help catching bugs.
d269cce
to
35c987e
Compare
35c987e
to
09293f7
Compare
I'm getting this runtime error on the Javascript build (
|
09293f7
to
0ae7870
Compare
The problem was is that the
@Faless, does this sound good to move forward with this PR? CC @reduz |
Oh, that's weird, it was only used in the RenderingDevice bit at first. Is this by design or a side effect of a refactoring @reduz ?
Oh, that explains why I was getting a deadlock on the threaded version. I'll make it return the value when known, |
0ae7870
to
1259eb7
Compare
He did the change in 77bc3e9, to add some threaded culling power to the renderer. @Faless, if you think this PR is good by itself, considering the worker threads issue has to be addressed separately, kindly approve this PR so it can be merged (sorry for insisting, but more PRs are being worked on top of this and I want to reduce the risk of rebase hell to a minimum). |
671f7e8
to
7f76c18
Compare
7f76c18
to
1f2d8ef
Compare
- Based on C++11's `thread` and `thread_local` - No more need to allocate-deallocate or check for null - No pointer anymore, just a member variable - Platform-specific implementations no longer needed (except for the few cases of non-portable functions) - Simpler for `NO_THREADS` - Thread ids are now the same across platforms (main is 1; others follow)
1f2d8ef
to
99fe462
Compare
Thanks! |
Was a regression from godotengine#45315. Fixes godotengine#46998.
Was a regression from godotengine#45315. Fixes godotengine#46998. (cherry picked from commit 7a64819)
(cherry picked from commit d1f023c)
SCons: Fix UWP build after #45315
Continuing with the effort started with
Mutex
andThread
, and following also what is possible now withSemaphore
,RWLock
is getting the same kind of changes.thread
andthread_local
NO_THREADS
NOTE: This is done on top of #45314, intended to be reviewed/merged after it. Anyway, the commit forUPDATE: Rebased after the other PR having been merged, so this is standalone now.Thread
can be checked separately.NOTE 2: There are still cases where you need to use
memnew(Thread)
and use it through a pointer. Namely, having a container ofThread
s, creating aThread
conditionally (unless the condition is about a non-threaded build) and usingThread
in a class that needs to be copied. Without adding move semantics, we can't do better.This code is generously donated by IMVU.