-
Notifications
You must be signed in to change notification settings - Fork 10.4k
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
[core] checking the status of thread creation #36510
base: master
Are you sure you want to change the base?
Conversation
It is possible for allocation of a system resource to fail. While the Thread abstraction in the core allows for a 'success' parameter, it is optional and not generally checked where used. This can lead to degenerate behavior which is hard to diagnose. In particular, the Executors assign Closures to their queues regardless of whether the thread handling to queue is actually running, leading those async requests to hang. This change makes the 'success' parameter required and tries to make the correct decision on how to proceed in the code where those Threads are started. For the Executor, we will attempt to carry on with the number of threads we were able to create. In other areas, we assert, assuming that whatever function is being performed by the allocated thread is critical to the overall function of the library. For the tests, we ignore the value of 'success' as we assume the tests will fail if thread creation failed. This is no different than the existing behavior.
Resubmitting original PR: #33286 |
/// is successfully created. | ||
/// The optional \a options can be used to set the thread detachable. | ||
Thread(const char* thd_name, void (*thd_body)(void* arg), void* arg, | ||
bool* success = nullptr, const Options& options = Options()); | ||
bool* success, const Options& options = Options()); |
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.
We still need old way of creating Thread because internal code (that you cannot access) still need this.
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.
Adding a new constructor that does not require a success
argument would undermine the point of this change. It would allow future code to use this constructor and thereby re-introduce the problem we have that pthread_create might fail and the result is a silent, slow degradation of functionality which is very difficult to diagnose.
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.
It'd be true but we cannot accept it without having a way to not break internal codes.
|
||
Thread(const char* thd_name, absl::AnyInvocable<void()> fn, | ||
bool* success = nullptr, const Options& options = Options()) | ||
Thread(const char* thd_name, absl::AnyInvocable<void()> fn, bool* success, |
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.
This too.
It is possible for allocation of a system resource to fail. While the Thread abstraction in the core allows for a 'success' parameter, it is optional and not generally checked where used. This can lead to degenerate behavior which is hard to diagnose. In particular, the Executors assign Closures to their queues regardless of whether the thread handling to queue is actually running, leading those async requests to hang.
This change makes the 'success' parameter required and tries to make the correct decision on how to proceed in the code where those Threads are started. For the Executor, we will attempt to carry on with the number of threads we were able to create. In other areas, we assert, assuming that whatever function is being performed by the allocated thread is critical to the overall function of the library.
For the tests, we ignore the value of 'success' as we assume the tests will fail if thread creation failed. This is no different than the existing behavior.