forest-net
an overlay networks for large-scale virtual worlds
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
testQuu.cpp
1 #include <iostream>
2 #include <thread>
3 #include <mutex>
4 #include <chrono>
5 #include "Quu.h"
6 
7 using std::thread;
8 using std::mutex;
9 using std::unique_lock;
10 using namespace std::chrono;
11 using std::cout;
12 using std::endl;
13 using namespace forest;
14 
15 Quu<pair<int,int>> myq(8);
16 
17 void prod(int i) {
18  pair<int,int> p; p.first = i;
19  for (int j = 0; j < 10; j++) {
20  p.second = j; myq.enq(p);
21  }
22 }
23 
24 
25 void cons() {
26  for (int i = 0; i < 100; i++) {
27  pair<int,int> p = myq.deq();
28  cout << p.first << " " << p.second << endl;
29  }
30 }
31 
32 int main () {
33  thread consumer(cons);
34  thread producer[10];
35 
36  for (int i = 0; i < 10; i++)
37  producer[i] = thread(prod,i);
38 
39  for (int i = 0; i < 10; i++)
40  producer[i].join();
41  consumer.join();
42 
43  return 0;
44 }