-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.cpp
37 lines (29 loc) · 820 Bytes
/
main.cpp
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
#include <iostream>
#include <stdio.h>
#include <unistd.h>
#include "EventCount.hpp"
void waiter(EventCount *eventCount) {
for (int i = 0; i < 100; i++) {
std::cout << "Preparing wait: " << i << std::endl;
auto key = eventCount->prepareWait();
eventCount->wait(key);
std::cout << "Got notification: " << i << std::endl;
}
}
void notifier(EventCount *eventCount) {
for (int i = 0; i < 100; i++) {
std::cout << "Notifying: " << i << std::endl;
eventCount->notify();
std::cout << "Notified: " << i << std::endl;
usleep(100);
}
}
int main(int argc, char **argv) {
EventCount eventCount;
std::thread t1(waiter, &eventCount);
usleep(1);
std::thread t2(notifier, &eventCount);
t1.join();
t2.join();
return 0;
}