MCPcopy Create free account
hub / github.com/cameron314/readerwriterqueue / threaded

Method threaded

tests/unittests/unittests.cpp:319–352  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

317 }
318
319 bool threaded()
320 {
321 weak_atomic<int> result;
322 result = 1;
323
324 ReaderWriterQueue<int> q(100);
325 SimpleThread reader([&]() {
326 int item;
327 int prevItem = -1;
328 for (int i = 0; i != 1000000; ++i) {
329 if (q.try_dequeue(item)) {
330 if (item <= prevItem) {
331 result = 0;
332 }
333 prevItem = item;
334 }
335 }
336 });
337 SimpleThread writer([&]() {
338 for (int i = 0; i != 1000000; ++i) {
339 if (((i >> 7) & 1) == 0) {
340 q.enqueue(i);
341 }
342 else {
343 q.try_enqueue(i);
344 }
345 }
346 });
347
348 writer.join();
349 reader.join();
350
351 return result.load() == 1 ? true : false;
352 }
353
354 bool peek()
355 {

Callers

nothing calls this directly

Calls 5

joinMethod · 0.80
loadMethod · 0.80
try_dequeueMethod · 0.45
enqueueMethod · 0.45
try_enqueueMethod · 0.45

Tested by

no test coverage detected