-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
61 lines (45 loc) · 1.33 KB
/
main.cpp
File metadata and controls
61 lines (45 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//
// main.cpp
// ConcurrentEvaluation
//
// Created by Wai Man Chan on 2/24/16.
// Copyright © 2016 Wai Man Chan. All rights reserved.
//
#include <iostream>
#include "ConcurrentInstance.hpp"
#include <boost/lockfree/queue.hpp>
struct entry {
unsigned int tid;
unsigned int lid;
};
void push(void*ptr, unsigned int threadID, unsigned int loopIndex) {
boost::lockfree::queue<entry> *queue = (boost::lockfree::queue<entry> *)ptr;
entry e;
e.tid = threadID;
e.lid = loopIndex;
queue->push(e);
}
void pop(void*ptr, unsigned int threadID, unsigned int loopIndex) {
boost::lockfree::queue<entry> *queue = (boost::lockfree::queue<entry> *)ptr;
entry e;
queue->pop(e);
}
int main(int argc, const char * argv[]) {
// insert code here...
//Test
boost::lockfree::queue<entry> queue(128);
testFieldContext context;
context.objPtr = &queue;
context.process = &push;
context.loop = 100000;
ConcurrentTestField *field = new ConcurrentTestField(100, context);
double pushTime = field->start();
printf("Push Time: %f\n", pushTime);
delete field;
context.process = &pop;
field = new ConcurrentTestField(100, context);
double popTime = field->start();
printf("Pop Time: %f\n", popTime);
delete field;
return 0;
}