aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2017-11-14 21:16:30 +0000
committerYann Herklotz <ymherklotz@gmail.com>2017-11-14 21:16:30 +0000
commit443ae47fc210bcfe10f6f6c5ac8aa3453e1d29d2 (patch)
tree4c06b7961a4f3e5fe1b67cb3c7d6290edcedc498 /tests
parente68759a4101567a27e306eae0a907baa759ae80c (diff)
downloadYAGE-443ae47fc210bcfe10f6f6c5ac8aa3453e1d29d2.tar.gz
YAGE-443ae47fc210bcfe10f6f6c5ac8aa3453e1d29d2.zip
Adding syncqueue
Diffstat (limited to 'tests')
-rw-r--r--tests/syncqueuetest.cpp46
1 files changed, 46 insertions, 0 deletions
diff --git a/tests/syncqueuetest.cpp b/tests/syncqueuetest.cpp
new file mode 100644
index 00000000..cb9a920e
--- /dev/null
+++ b/tests/syncqueuetest.cpp
@@ -0,0 +1,46 @@
+#include <yage.h>
+
+#include <atomic>
+#include <thread>
+
+using namespace yage;
+
+SyncQueue<int> queue;
+std::atomic_int j;
+
+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()
+{
+ j.store(0);
+ 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";
+}