-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[libc++] cv-qualified types in atomic and atomic_ref (P3323R1) #121414
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
5afe474
fc886c3
69d92fa
9c6dd66
1077d03
28a0107
26013d0
ffdda72
1b24aeb
a2f7780
9ec6b04
d878901
f350f7f
b156123
e0fd1a2
0b96b4c
dcbee5b
232a8a5
d84ec1f
afe849f
b8a4edc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -45,12 +45,12 @@ template <class T, class StoreOp, class LoadOp> | |||||||||
void test_seq_cst(StoreOp store_op, LoadOp load_op) { | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we introduce |
||||||||||
#ifndef TEST_HAS_NO_THREADS | ||||||||||
for (int i = 0; i < 100; ++i) { | ||||||||||
T old_value(make_value<T>(0)); | ||||||||||
T new_value(make_value<T>(1)); | ||||||||||
T old_value(make_value<std::remove_cv_t<T>>(0)); | ||||||||||
T new_value(make_value<std::remove_cv_t<T>>(1)); | ||||||||||
Comment on lines
+48
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
||||||||||
T copy_x = old_value; | ||||||||||
T copy_x = const_cast<std::remove_cv_t<T> const&>(old_value); | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't understand why this needs a |
||||||||||
std::atomic_ref<T> const x(copy_x); | ||||||||||
T copy_y = old_value; | ||||||||||
T copy_y = const_cast<std::remove_cv_t<T> const&>(old_value); | ||||||||||
std::atomic_ref<T> const y(copy_y); | ||||||||||
|
||||||||||
std::atomic_bool x_updated_first(false); | ||||||||||
|
@@ -61,19 +61,19 @@ void test_seq_cst(StoreOp store_op, LoadOp load_op) { | |||||||||
auto t2 = support::make_test_thread([&] { store_op(y, old_value, new_value); }); | ||||||||||
|
||||||||||
auto t3 = support::make_test_thread([&] { | ||||||||||
while (!equals(load_op(x), new_value)) { | ||||||||||
while (!equals(load_op(x), const_cast<std::remove_cv_t<T> const&>(new_value))) { | ||||||||||
std::this_thread::yield(); | ||||||||||
} | ||||||||||
if (!equals(load_op(y), new_value)) { | ||||||||||
if (!equals(load_op(y), const_cast<std::remove_cv_t<T> const&>(new_value))) { | ||||||||||
x_updated_first.store(true, std::memory_order_relaxed); | ||||||||||
} | ||||||||||
}); | ||||||||||
|
||||||||||
auto t4 = support::make_test_thread([&] { | ||||||||||
while (!equals(load_op(y), new_value)) { | ||||||||||
while (!equals(load_op(y), const_cast<std::remove_cv_t<T> const&>(new_value))) { | ||||||||||
std::this_thread::yield(); | ||||||||||
} | ||||||||||
if (!equals(load_op(x), new_value)) { | ||||||||||
if (!equals(load_op(x), const_cast<std::remove_cv_t<T> const&>(new_value))) { | ||||||||||
y_updated_first.store(true, std::memory_order_relaxed); | ||||||||||
} | ||||||||||
}); | ||||||||||
|
@@ -98,10 +98,10 @@ template <class T, class StoreOp, class LoadOp> | |||||||||
void test_acquire_release(StoreOp store_op, LoadOp load_op) { | ||||||||||
#ifndef TEST_HAS_NO_THREADS | ||||||||||
for (auto i = 0; i < 100; ++i) { | ||||||||||
T old_value(make_value<T>(0)); | ||||||||||
T new_value(make_value<T>(1)); | ||||||||||
T old_value(make_value<std::remove_cv_t<T>>(0)); | ||||||||||
T new_value(make_value<std::remove_cv_t<T>>(1)); | ||||||||||
|
||||||||||
T copy = old_value; | ||||||||||
T copy = const_cast<std::remove_cv_t<T> const&>(old_value); | ||||||||||
std::atomic_ref<T> const at(copy); | ||||||||||
int non_atomic = 5; | ||||||||||
|
||||||||||
|
@@ -110,14 +110,15 @@ void test_acquire_release(StoreOp store_op, LoadOp load_op) { | |||||||||
threads.reserve(number_of_threads); | ||||||||||
|
||||||||||
for (auto j = 0; j < number_of_threads; ++j) { | ||||||||||
threads.push_back(support::make_test_thread([&at, &non_atomic, load_op, new_value] { | ||||||||||
while (!equals(load_op(at), new_value)) { | ||||||||||
std::this_thread::yield(); | ||||||||||
} | ||||||||||
// Other thread's writes before the release store are visible | ||||||||||
// in this thread's read after the acquire load | ||||||||||
assert(non_atomic == 6); | ||||||||||
})); | ||||||||||
threads.push_back(support::make_test_thread( | ||||||||||
[&at, &non_atomic, load_op, new_value = const_cast<std::remove_cv_t<T> const&>(new_value)] { | ||||||||||
while (!equals(load_op(at), new_value)) { | ||||||||||
std::this_thread::yield(); | ||||||||||
} | ||||||||||
// Other thread's writes before the release store are visible | ||||||||||
// in this thread's read after the acquire load | ||||||||||
assert(non_atomic == 6); | ||||||||||
})); | ||||||||||
} | ||||||||||
|
||||||||||
non_atomic = 6; | ||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.