-
Notifications
You must be signed in to change notification settings - Fork 0
/
RingbufferInnlevering.cpp
85 lines (53 loc) · 1.24 KB
/
RingbufferInnlevering.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// RingbufferInnlevering.cpp : This file contains the 'main' function. Program execution begins and ends there.
//
#include "pch.h"
#include <iostream>
#include "ring.cpp"
#include <thread>
void writer(RingBuffer<char>& buffer);
void reader(RingBuffer<char>& buffer);
void keyboardInput(RingBuffer<char>& buffer);
int main()
{
RingBuffer<char> RingBuffer(5); //BigDaddy
thread writerThread(&writer, ref(RingBuffer)); //child
thread keyboardInputThread(&keyboardInput, ref(RingBuffer)); //child
thread readerThread(&reader, ref(RingBuffer)); //child
keyboardInputThread.join();
writerThread.join();
readerThread.join();
return 0; //yey
}
void writer(RingBuffer<char>& buffer)
{
string s = "0123456789";
for (char c : s)
{
buffer.put(c);
this_thread::sleep_for(chrono::milliseconds(200));
}
};
void keyboardInput(RingBuffer<char>& buffer)
{
string s;
do
{
cin >> s;
{
for (char c : s)
{
buffer.put(c);
}
}
} while (s != "EXIT");
};
void reader(RingBuffer<char>& buffer)
{
while ((true))
{
char tmp;
tmp = buffer.get();
this_thread::sleep_for(chrono::milliseconds(1000));
cout << tmp;
}
};