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

[core] checking the status of thread creation #36510

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chansen3
Copy link

@chansen3 chansen3 commented May 2, 2024

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.

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.
@chansen3
Copy link
Author

chansen3 commented May 2, 2024

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());
Copy link
Contributor

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.

Copy link
Author

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.

Copy link
Contributor

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,
Copy link
Contributor

Choose a reason for hiding this comment

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

This too.

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

Successfully merging this pull request may close these issues.

None yet

5 participants