From 8f92d9d851bc8fc3c19f943c30f91b7a43ddb167 Mon Sep 17 00:00:00 2001 From: Tor Brede Vekterli Date: Thu, 17 Feb 2022 13:49:14 +0000 Subject: Ensure cross-thread visibility in test --- fnet/src/tests/frt/rpc/detach_return_invoke.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'fnet') diff --git a/fnet/src/tests/frt/rpc/detach_return_invoke.cpp b/fnet/src/tests/frt/rpc/detach_return_invoke.cpp index e3c238cf633..17c38ab6e3a 100644 --- a/fnet/src/tests/frt/rpc/detach_return_invoke.cpp +++ b/fnet/src/tests/frt/rpc/detach_return_invoke.cpp @@ -5,15 +5,16 @@ #include #include #include +#include #include struct Receptor : public FRT_IRequestWait { - FRT_RPCRequest *req; + std::atomic req; - Receptor() : req(0) {} + Receptor() : req(nullptr) {} void RequestDone(FRT_RPCRequest *r) override { - req = r; + req.store(r); } }; @@ -55,18 +56,18 @@ TEST("detach return invoke") { target->InvokeSync(req, 5.0); EXPECT_TRUE(!req->IsError()); for (uint32_t i = 0; i < 1000; ++i) { - if (receptor.req != 0) { + if (receptor.req.load() != nullptr) { break; } std::this_thread::sleep_for(10ms); } req->SubRef(); target->SubRef(); - if (receptor.req != 0) { - EXPECT_TRUE(!receptor.req->IsError()); - receptor.req->SubRef(); + if (receptor.req.load() != nullptr) { + EXPECT_TRUE(!receptor.req.load()->IsError()); + receptor.req.load()->SubRef(); } - EXPECT_TRUE(receptor.req != 0); + EXPECT_TRUE(receptor.req.load() != nullptr); }; TEST_MAIN() { TEST_RUN_ALL(); } -- cgit v1.2.3