File tree Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Expand file tree Collapse file tree 2 files changed +31
-2
lines changed Original file line number Diff line number Diff line change @@ -72,7 +72,7 @@ inline void yield(K& k) noexcept {
72
72
++k;
73
73
}
74
74
75
- template <std::size_t N = 4096 , typename K, typename F>
75
+ template <std::size_t N = 32 , typename K, typename F>
76
76
inline void sleep (K& k, F&& f) {
77
77
if (k < static_cast <K>(N)) {
78
78
std::this_thread::yield ();
@@ -84,7 +84,7 @@ inline void sleep(K& k, F&& f) {
84
84
++k;
85
85
}
86
86
87
- template <std::size_t N = 4096 , typename K>
87
+ template <std::size_t N = 32 , typename K>
88
88
inline void sleep (K& k) {
89
89
sleep<N>(k, [] {
90
90
std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
Original file line number Diff line number Diff line change @@ -160,4 +160,33 @@ TEST(Sync, Condition) {
160
160
cond.broadcast ();
161
161
162
162
for (auto &t : test_conds) t.join ();
163
+ }
164
+
165
+ TEST (Sync, ConditionRobust) {
166
+ printf (" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 1\n " );
167
+ ipc::sync::condition cond {" test-cond" };
168
+ printf (" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 2\n " );
169
+ ipc::sync::mutex lock {" test-mutex" };
170
+ printf (" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 3\n " );
171
+ lock.lock ();
172
+ std::thread unlock {[] {
173
+ printf (" WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW 1\n " );
174
+ ipc::sync::condition cond {" test-cond" };
175
+ printf (" WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW 2\n " );
176
+ ipc::sync::mutex lock {" test-mutex" };
177
+ printf (" WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW 3\n " );
178
+ {
179
+ std::lock_guard<ipc::sync::mutex> guard {lock};
180
+ }
181
+ std::this_thread::sleep_for (std::chrono::seconds (1 ));
182
+ printf (" WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW 4\n " );
183
+ cond.notify ();
184
+ printf (" WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW 5\n " );
185
+ }};
186
+ printf (" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 4\n " );
187
+ cond.wait (lock);
188
+ printf (" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 5\n " );
189
+ lock.unlock ();
190
+ printf (" XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX 6\n " );
191
+ unlock.join ();
163
192
}
You can’t perform that action at this time.
0 commit comments