-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyMutex.cpp
More file actions
44 lines (38 loc) · 751 Bytes
/
myMutex.cpp
File metadata and controls
44 lines (38 loc) · 751 Bytes
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
#include <measureLatency.h>
#include <iostream>
#include <thread>
#include <pthread.h>
using namespace std;
class MyMutex
{
private:
pthread_mutex_t _mutex;
public:
MyMutex()
{
pthread_mutex_init(&_mutex, NULL);
}
void lock()
{
pthread_mutex_lock(&_mutex);
}
void unlock()
{
pthread_mutex_unlock(&_mutex);
}
};
int main(int argc, char* argv[])
{
MyMutex m;
auto res = test([](MyMutex& m)
{
const int LOOP {1000};
for (int i=0; i<LOOP; ++i)
{
m.lock();
m.unlock();
}
return LOOP;
}, m);
cout << "Function ran for " << duration_cast<nanoseconds>( res.second ).count()/res.first << " ns " << endl;
}