MCPcopy Create free account
hub / github.com/catboost/catboost / RunReadersWriters

Method RunReadersWriters

util/system/rwlock_ut.cpp:59–83  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57 }
58
59 void RunReadersWriters() {
60 if (Id_ % 2 == 0) {
61 for (size_t i = 0; i < 10; ++i) {
62 Data_.mutex.AcquireRead();
63
64 ++Data_.readersIn;
65 FAIL_ASSERT(Data_.writersIn.load() == 0);
66 usleep(RandomNumber<ui32>() % 5);
67 --Data_.readersIn;
68
69 Data_.mutex.ReleaseRead();
70 }
71 } else {
72 for (size_t i = 0; i < 10; ++i) {
73 Data_.mutex.AcquireWrite();
74
75 ++Data_.writersIn;
76 FAIL_ASSERT(Data_.readersIn.load() == 0 && Data_.writersIn.load() == 1);
77 usleep(RandomNumber<ui32>() % 5);
78 --Data_.writersIn;
79
80 Data_.mutex.ReleaseWrite();
81 }
82 }
83 }
84#undef FAIL_ASSERT
85
86 private:

Callers

nothing calls this directly

Calls 6

usleepFunction · 0.85
AcquireReadMethod · 0.80
ReleaseReadMethod · 0.80
AcquireWriteMethod · 0.80
ReleaseWriteMethod · 0.80
loadMethod · 0.45

Tested by

no test coverage detected