data race test
This commit is contained in:
parent
4c008aa77c
commit
8d0fd6ccdb
@ -11,8 +11,8 @@ file(GLOB prj_src src/*)
|
|||||||
|
|
||||||
target_sources(${PROJECT_NAME} PRIVATE ${prj_src})
|
target_sources(${PROJECT_NAME} PRIVATE ${prj_src})
|
||||||
|
|
||||||
# target_compile_options(${PROJECT_NAME} PRIVATE -fsanitize=thread)
|
target_compile_options(${PROJECT_NAME} PRIVATE -fsanitize=thread)
|
||||||
# target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=thread)
|
target_link_options(${PROJECT_NAME} PRIVATE -fsanitize=thread)
|
||||||
|
|
||||||
add_subdirectory(bench)
|
add_subdirectory(bench)
|
||||||
add_subdirectory(tests)
|
add_subdirectory(tests)
|
||||||
@ -12,5 +12,5 @@ target_link_libraries(${NAME} PRIVATE
|
|||||||
${PROJECT_NAME}
|
${PROJECT_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
# target_compile_options(${NAME} PRIVATE -fsanitize=thread)
|
target_compile_options(${NAME} PRIVATE -fsanitize=thread)
|
||||||
# target_link_options(${NAME} PRIVATE -fsanitize=thread)
|
target_link_options(${NAME} PRIVATE -fsanitize=thread)
|
||||||
@ -36,8 +36,7 @@ class Logger {
|
|||||||
template <typename Metric,
|
template <typename Metric,
|
||||||
typename = std::enable_if_t<std::is_arithmetic_v<Metric>>>
|
typename = std::enable_if_t<std::is_arithmetic_v<Metric>>>
|
||||||
void add(const std::string& field, Metric metric) {
|
void add(const std::string& field, Metric metric) {
|
||||||
auto locked = active.load(std::memory_order_acquire);
|
std::shared_ptr<map_type> locked = active.load(std::memory_order_acquire);
|
||||||
// auto locked = active;
|
|
||||||
auto it = locked->find(field);
|
auto it = locked->find(field);
|
||||||
if (it == locked->end()) {
|
if (it == locked->end()) {
|
||||||
throw configErrorMsg; // additional 30ns on bench ?
|
throw configErrorMsg; // additional 30ns on bench ?
|
||||||
|
|||||||
@ -68,18 +68,22 @@ void Logger::Worker::unroll() {
|
|||||||
if (!parent.isConfigured())
|
if (!parent.isConfigured())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto tmp = parent.active.load(std::memory_order_acquire);
|
auto tmp = parent.active.load(std::memory_order_relaxed);
|
||||||
// auto tmp = parent.active;
|
|
||||||
auto toBeActive = tmp == parent.m1 ? parent.m2 : parent.m1;
|
auto toBeActive = tmp == parent.m1 ? parent.m2 : parent.m1;
|
||||||
while (!parent.active.compare_exchange_weak(tmp, toBeActive)) {
|
|
||||||
std::this_thread::yield();
|
|
||||||
}
|
|
||||||
// parent.active = toBeActive;
|
|
||||||
|
|
||||||
|
parent.active.store(toBeActive, std::memory_order_release);
|
||||||
|
|
||||||
|
// hmm, seems that we can receive situation here there use_count is less or
|
||||||
|
// equal 2 but in reality we still have instance how? store and load is
|
||||||
|
// tighted, so we have guarantee that this check will be happens before
|
||||||
while (tmp.use_count() > 2) {
|
while (tmp.use_count() > 2) {
|
||||||
std::this_thread::yield();
|
std::this_thread::yield();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// it's needed thread fence to guarantee use count change
|
||||||
|
// __tsan_acquire(tmp.use_count());
|
||||||
|
std::atomic_thread_fence(std::memory_order_acquire);
|
||||||
|
|
||||||
// at this place we are guarantee that tmp is only ours or not?
|
// at this place we are guarantee that tmp is only ours or not?
|
||||||
std::string output;
|
std::string output;
|
||||||
bool haveToPush{false};
|
bool haveToPush{false};
|
||||||
|
|||||||
@ -12,5 +12,5 @@ target_link_libraries(${NAME} PRIVATE
|
|||||||
${PROJECT_NAME}
|
${PROJECT_NAME}
|
||||||
)
|
)
|
||||||
|
|
||||||
# target_compile_options(${NAME} PRIVATE -fsanitize=thread)
|
target_compile_options(${NAME} PRIVATE -fsanitize=thread)
|
||||||
# target_link_options(${NAME} PRIVATE -fsanitize=thread)
|
target_link_options(${NAME} PRIVATE -fsanitize=thread)
|
||||||
Loading…
x
Reference in New Issue
Block a user