-
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Allow list initialization of thread::attributes #70
Comments
Using a separate attributes structure to initialise various objects is a POSIX trick in C to avoid changing the API when adding new members to the structure, and for those using the C API probably there is not much to do. However, in C++ life is a bit better, and we have the luxury of multiple constructors, so I think that your proposal makes sense, and not only for threads, but possibly for other objects that use attributes. The only thing that we have to be very careful when adding the new constructors is to leave space for incremental updates, which, as far as I can tell at first sight, probably means not using defaults, but defining separate constructors with 1, 2, 3, ... parameters. Could you study if such a solution is realistic? |
That seems to be the most straightforward way class attributes
{
// allocated stack with default size and default priority or non-default priority
// forward to second constructor
attributes(priority_t = priority::normal);
// allocated stack and default priority or non-default priority
attributes(std::size_t, priority_t = priority::normal);
// provided stack and default priority or non-default priority
attributes(void*, std::size_t, priority_t = priority::normal);
private:
void* th_stack_address;
std::size_t th_stack_size;
priority_t th_priority;
} Some constructors needs to be marked as explicit and/or scoped enums need to be used in order to prevent direct conversion from integer types: When looking at the code I thought it might also be helpful to
|
I guess it might eventually work, but I'm not convinced that using defaults is a good idea.
What exactly do you mean by this? I have to read the C++20 specs for |
I would like do do something like this
Since there is only a default constructor for
thread::attributes
I have do do thisA practical use case is having
thread
as member of a class with the need to initialize via the member initializer list.This doesn't work:
so I have to use this workaround
The text was updated successfully, but these errors were encountered: