-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
<memory>: Fix atomic smart pointers array type interaction #1339
<memory>: Fix atomic smart pointers array type interaction #1339
Conversation
Same tests as for the normal atomic smart pointer with non-array element. The array pointers should behave exactly the same as the normal pointers.
Fix atomic smart pointers with array elements by making the internal type match that of [weak|shared]_ptr::element_type by removing the extent of the arrays.
Thanks! Should there be test coverage for multidimensional arrays? (This is the first thing I think of when I see |
Add a test that checks that the atomic smart pointers with multidimensional arrays compiles.
Added a compile test for multidimensional arrays (member and non-member functions). If you also want to test the functionality I think the best thing is to just repeat the original test for the different types. Could refactor it into template functions. As originally noted the test do not touch the Otherwise I could not think of a simple way to test whether it compiles except writing some producer/consumer type of functions which use |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
STL/tests/std/tests/P1135R6_atomic_wait/test.cpp is where atomic wait is tested |
Update P1135R6_atomic_wait test to include smart pointers holding arrays.
…_ptr Increase waiting_duration timing assumption for test_notify_all_notifies_all_ptr because it might have cause some flakiness for the test runners.
I noticed that this issue[#1332] was still not fixed and had some time over so added test for smart pointer array types in I used the already created, but unused, Maybe it should be a separate low priority issue to rewrite As for #1332, what is required to close this issue? |
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.
Notes:
This in theory changes ABI of _Atomic_ptr_base
; however, it only changes name manglings of non-public names, and changes the members of _Atomic_ptr_base<T[]>
from:
{
atomic<T(*)[]> _Ptr;
_Locked_pointer<_Ref_count_base> _Repptr;
}
to
{
atomic<T*> _Ptr;
_Locked_pointer<_Ref_count_base> _Repptr;
}
which should not change ABI/layout at all.
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.
_Seed
should not be a template, since there's no reason for it to be a template. Additionally, an existing, correct, narrowing conversion now fails.
Bug in VS code ended up making a comment meant for 2693 on this PR
// increased waiting_duration because timing assumption might not hold for atomic smart pointers | ||
test_notify_all_notifies_all_impl<std::atomic, UnderlyingType>(old_value, new_value, 3 * waiting_duration); |
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.
I'm slightly concerned about this change because the test suite should never contain timing assumptions that could lead to sporadic failures. That said, no change requested, because this is clearly a pre-existing issue.
test_notify_all_notifies_all_ptr(std::make_shared<int>('a'), std::make_shared<int>('a'), waiting_duration); | ||
test_notify_all_notifies_all_ptr( | ||
std::weak_ptr{std::make_shared<int>('a')}, std::weak_ptr{std::make_shared<int>('a')}, waiting_duration); |
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.
No change requested: Nice catch, test_notify_all_notifies_all_ptr()
was defined but never used before.
@@ -3872,7 +3873,7 @@ protected: | |||
_Ptr.notify_all(); | |||
} | |||
|
|||
atomic<_Ty*> _Ptr{nullptr}; | |||
atomic<remove_extent_t<_Ty>*> _Ptr{nullptr}; |
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.
No change requested: Regarding the ABI implications that @strega-nil-ms mentioned in #1339 (review) - while changing data members is always concerning from an ABI perspective, I agree that the actual bits being stored are the same. Additionally, the previous code would generally fail to compile for simple cases like store()
, which indicates that we shouldn't have to worry about mismatch issues. (The one time we can make unrestricted changes to layout is when the code couldn't compile at all before - this is not quite "wouldn't compile at all" but close.)
@@ -228,6 +229,21 @@ inline void test_atomic_wait() { | |||
test_atomic_wait_func_ptr(std::make_shared<int>('a'), std::make_shared<int>('a'), waiting_duration); | |||
test_atomic_wait_func_ptr( | |||
std::weak_ptr{std::make_shared<int>('a')}, std::weak_ptr{std::make_shared<int>('a')}, waiting_duration); | |||
test_atomic_wait_func_ptr(std::make_shared<int[]>(0), std::make_shared<int[]>(0), waiting_duration); |
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.
No change requested: I note that the zero-runtime-length arrays being used in the test cases are unusual; however, I believe this is conforming, and the code also tests one-element arrays, so I have no objection to this (even if I would have used non-zero numbers for all).
} | ||
if (instance.compare_exchange_strong(loaded, constInstance)) { |
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.
No change requested: We conventionally add newlines between non-chained if
-statements. However, this was copied from pre-existing code immediately above, and it's not worth resetting testing by pushing a commit.
I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed. |
Thanks for fixing this bug, and congratulations on your first microsoft/STL commit! 🎉 😸 🚀 (And apologies for taking so long to review this! 🙀) |
Fixes #1332
Notes
Have not tested if it affects
wait
,notify_one
andnotify_all
. Not that it should, but I am not well versed in the smart pointer implementations.