From fb8197839c0bebc20fd68ee3f280da934c49c473 Mon Sep 17 00:00:00 2001 From: Yann Herklotz Date: Fri, 22 Dec 2017 21:16:02 +0000 Subject: Removing editor and refactoring code. --- tests/syncqueue/test.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/syncqueue/test.cpp (limited to 'tests/syncqueue/test.cpp') diff --git a/tests/syncqueue/test.cpp b/tests/syncqueue/test.cpp new file mode 100644 index 00000000..1d7d8037 --- /dev/null +++ b/tests/syncqueue/test.cpp @@ -0,0 +1,53 @@ +/** --------------------------------------------------------------------------- + * @file: syncqueuetest.cpp + * + * Copyright (c) 2017 Yann Herklotz Grave + * MIT License, see LICENSE file for more details. + * ---------------------------------------------------------------------------- + */ + +#include + +#include +#include + +using namespace yage; + +SyncQueue queue; +std::atomic_int j(0); + +void push_to_queue1(int elements) +{ + for (int i = 0; i < elements; i++) { + queue.push(1); + j.fetch_add(1, std::memory_order_relaxed); + } + std::cout << "Done 1\n"; +} + +void push_to_queue2(int elements) +{ + for (int i = 0; i < elements; i++) { + queue.push(2); + j.fetch_add(1, std::memory_order_relaxed); + } + std::cout << "Done 2\n"; +} + +int main() +{ + std::thread first(push_to_queue1, 100000); + std::thread second(push_to_queue2, 100000); + + std::cout << "created threads, now adding in main\n"; + for (int i = 0; i < 1000000; ++i) { + queue.push(i); + j.fetch_add(1, std::memory_order_relaxed); + } + + std::cout << "now joining the threads\n"; + first.join(); + second.join(); + std::cout << "done\n" + << "iterations: " << j << "\n"; +} -- cgit