Refactors parallel barrier test
[libcds.git] / benchmark-drivers / fcstack_driver.cpp
1 #include <cds/gc/dhp.h>
2 #include <cds/gc/hp.h>
3 #include <cds/init.h>
4 #include <cds/intrusive/fcstack.h>
5 #include <iostream>
6 #include <list>
7 #include <string>
8
9 using namespace std;
10
11 namespace ci = cds::intrusive;
12 typedef cds::gc::HP hp_gc;
13
14 struct Foo : boost::intrusive::list_base_hook<> {
15   Foo(int x) : x(x) {}
16   int x;
17 };
18
19 typedef ci::FCStack<Foo> MyStack;
20
21 int main() {
22   cds::Initialize();
23
24   {
25     // Initialize Hazard Pointer singleton
26     cds::gc::HP hpGC(128, 8, 128);
27     // If main thread uses lock-free containers
28     // the main thread should be attached to libcds infrastructure
29     cds::threading::Manager::attachThread();
30
31     MyStack s;
32     Foo *f = new Foo(1);
33     Foo *res = nullptr;
34     s.push(*f);
35     res = s.pop();
36     if (res) {
37       cout << "Dequeued " << res->x << "\n";
38     } else {
39       cout << "Dequeued none\n\n";
40     }
41   }
42
43   cds::Terminate();
44   return 0;
45 }