File tree 1 file changed +11
-10
lines changed
1 file changed +11
-10
lines changed Original file line number Diff line number Diff line change 1
1
#include < algorithm>
2
- #include < thread>
3
2
#include < catch2/catch_test_macros.hpp>
3
+ #include < thread>
4
4
5
5
#include " lockfree.hpp"
6
6
@@ -332,23 +332,24 @@ TEST_CASE("Multithreaded read/write", "[rb_multi]") {
332
332
333
333
// consumer
334
334
threads.emplace_back ([&]() {
335
- bool read_success = false ;
336
335
uint64_t data[1 ] = {0 };
337
336
do {
338
- read_success = rb.Read (data, 1 );
337
+ bool read_success = rb.Read (data, 1 );
339
338
if (read_success) {
340
339
read .push_back (data[0 ]);
341
340
}
342
- } while (!read_success || data[0 ] < 2047 );
341
+ } while (data[0 ] < 2047 );
343
342
});
344
343
// producer
345
344
threads.emplace_back ([&]() {
346
- uint64_t data[1 ] = {0 };
347
- for (uint64_t idx = 0 ; idx < 2048 ; idx++) {
348
- data[0 ] = idx;
349
- written.push_back (idx);
350
- rb.Write (data, 1 );
351
- }
345
+ uint64_t cnt = 0 ;
346
+ do {
347
+ bool write_success = rb.Write (&cnt, 1 );
348
+ if (write_success) {
349
+ written.push_back (cnt);
350
+ cnt++;
351
+ }
352
+ } while (cnt < 2048 );
352
353
});
353
354
for (auto &t : threads) {
354
355
t.join ();
You can’t perform that action at this time.
0 commit comments