From 80e1f38bea291f1b2eb326882b2041db69b9bd47 Mon Sep 17 00:00:00 2001 From: Megvii Engine Team Date: Mon, 23 May 2022 19:08:12 +0800 Subject: [PATCH] fix(gtest): fix ci error report stack-use-after-scope how to reproduce the problem: 1: build with asan(revert this MR) 2: then taskset process to one cpu: taskset 01 ./megbrain_test --gtest_filter=TestAsyncQueue.SynchronizerWaiterStarving GitOrigin-RevId: eb6f7aa4d889d0be86294666ed24996d8b8cae4c --- src/core/test/utils/thread.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/test/utils/thread.cpp b/src/core/test/utils/thread.cpp index d46e0fba..3570f9e7 100644 --- a/src/core/test/utils/thread.cpp +++ b/src/core/test/utils/thread.cpp @@ -169,9 +169,16 @@ TEST(TestAsyncQueue, SynchronizerMultiProducer3) { test_scq_sync_multi_producer<100, 100>(); } +//! asan error report stack-use-after-scope when +//! only have one physics cpu or bind to one core +//! with taskset 01 xxx, move processed to global +//! var as a workaround. +namespace { +std::atomic_size_t processed{0}; +} TEST(TestAsyncQueue, SynchronizerWaiterStarving) { SCQueueSynchronizer sync(0); - std::atomic_size_t processed{0}; + processed = 0; auto worker = [&]() { while (sync.consumer_fetch(1)) { for (int volatile i = 0; i < 1000; ++i)