summaryrefslogtreecommitdiffstats
path: root/fnet
diff options
context:
space:
mode:
authorTor Brede Vekterli <vekterli@yahooinc.com>2022-02-17 13:49:14 +0000
committerTor Brede Vekterli <vekterli@yahooinc.com>2022-02-18 15:38:33 +0000
commit8f92d9d851bc8fc3c19f943c30f91b7a43ddb167 (patch)
treeef259bfd2afe7d2bb29aedbab52d62f77df30704 /fnet
parent0c645c88164bc29c64aaa1861b73aaaae443e075 (diff)
Ensure cross-thread visibility in test
Diffstat (limited to 'fnet')
-rw-r--r--fnet/src/tests/frt/rpc/detach_return_invoke.cpp17
1 files changed, 9 insertions, 8 deletions
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 <vespa/fnet/frt/rpcrequest.h>
#include <vespa/fnet/frt/invoker.h>
#include <vespa/vespalib/util/stringfmt.h>
+#include <atomic>
#include <thread>
struct Receptor : public FRT_IRequestWait
{
- FRT_RPCRequest *req;
+ std::atomic<FRT_RPCRequest*> 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(); }