Mir

Merge lp:~albaguirre/mir/fix-data-race-in-client-test into lp:mir

Proposed by Alberto Aguirre
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 2734
Proposed branch: lp:~albaguirre/mir/fix-data-race-in-client-test
Merge into: lp:mir
Diff against target: 20 lines (+2/-1)
1 file modified
tests/acceptance-tests/test_client_library.cpp (+2/-1)
To merge this branch: bzr merge lp:~albaguirre/mir/fix-data-race-in-client-test
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Chris Halse Rogers Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+264203@code.launchpad.net

Commit message

Fix data race in ClientLibrary.client_library_accesses_and_advances_buffers

Description of the change

Fix data race in ClientLibrary.client_library_accesses_and_advances_buffers

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Chris Halse Rogers (raof) wrote :

This isn't actually a data race; every access to buffers is synchronised.

That said, it's harmless, so if it silences a warning...

review: Approve
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

> This isn't actually a data race;

It is most certainly a data race. The race is between next_buffer called by the rpc thread and " EXPECT_THAT(buffers, Eq(1));" There's no synchronization between those two threads in regards to the member "buffers".

Revision history for this message
Chris Halse Rogers (raof) wrote :

All of the EXPECT_THAT(buffers, ...) calls I can see are synchronised by a previous mir_wait_for() call; am I missing one?

Revision history for this message
Alberto Aguirre (albaguirre) wrote :

But that doesn't guarantee synchronization for "buffers". The data needs to be protected with the same mutex when writing and reading from (or use atomic writes/reads) otherwise there are no guarantees on memory ordering.

Revision history for this message
Chris Halse Rogers (raof) wrote :

Ah, true, and somewhat unintuitive. Yay threading!

Revision history for this message
Daniel van Vugt (vanvugt) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/acceptance-tests/test_client_library.cpp'
2--- tests/acceptance-tests/test_client_library.cpp 2015-07-02 03:53:29 +0000
3+++ tests/acceptance-tests/test_client_library.cpp 2015-07-08 21:31:15 +0000
4@@ -39,6 +39,7 @@
5
6 #include <gtest/gtest.h>
7 #include <gmock/gmock.h>
8+#include <atomic>
9 #include <chrono>
10 #include <thread>
11 #include <cstring>
12@@ -60,7 +61,7 @@
13 std::set<MirSurface*> surfaces;
14 MirConnection* connection = nullptr;
15 MirSurface* surface = nullptr;
16- int buffers = 0;
17+ std::atomic<int> buffers{0};
18
19 static void connection_callback(MirConnection* connection, void* context)
20 {

Subscribers

People subscribed via source and target branches