From 407fdc3a3612933da66e7532124ab58f1d63071e Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Wed, 8 Jul 2020 22:13:43 -0700 Subject: [PATCH] Fix data race in RpcWithEarlyFreeRequest by using atomics --- test/cpp/end2end/message_allocator_end2end_test.cc | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/test/cpp/end2end/message_allocator_end2end_test.cc b/test/cpp/end2end/message_allocator_end2end_test.cc index a54e03a744a..95bf7f4faa1 100644 --- a/test/cpp/end2end/message_allocator_end2end_test.cc +++ b/test/cpp/end2end/message_allocator_end2end_test.cc @@ -17,6 +17,7 @@ */ #include +#include #include #include #include @@ -235,8 +236,8 @@ class SimpleAllocatorTest : public MessageAllocatorEnd2endTestBase { class MessageHolderImpl : public experimental::MessageHolder { public: - MessageHolderImpl(int* request_deallocation_count, - int* messages_deallocation_count) + MessageHolderImpl(std::atomic_int* request_deallocation_count, + std::atomic_int* messages_deallocation_count) : request_deallocation_count_(request_deallocation_count), messages_deallocation_count_(messages_deallocation_count) { set_request(new EchoRequest); @@ -261,8 +262,8 @@ class SimpleAllocatorTest : public MessageAllocatorEnd2endTestBase { } private: - int* request_deallocation_count_; - int* messages_deallocation_count_; + std::atomic_int* const request_deallocation_count_; + std::atomic_int* const messages_deallocation_count_; }; experimental::MessageHolder* AllocateMessages() override { @@ -271,8 +272,8 @@ class SimpleAllocatorTest : public MessageAllocatorEnd2endTestBase { &messages_deallocation_count); } int allocation_count = 0; - int request_deallocation_count = 0; - int messages_deallocation_count = 0; + std::atomic_int request_deallocation_count{0}; + std::atomic_int messages_deallocation_count{0}; }; };