5
5
### Thread-safe container for sharing data between threads. Header-only.
6
6
7
7
* Thread-safe push and fetch.
8
- * Use stream operators to push (>> ) and fetch (<< ) items.
8
+ * Use stream operators to push (<< ) and fetch (>> ) items.
9
9
* Blocking (forever waiting to fetch).
10
10
* Range-based for loop supported.
11
11
* Close to prevent pushing and stop waiting to fetch.
12
12
* Integrates well with STL algorithms. Eg: std::move(ch.begin(), ch.end(), ...).
13
- * Tested with GCC and Clang .
13
+ * Tested with GCC, Clang, and MSVC .
14
14
15
15
## Requirements
16
16
@@ -36,10 +36,10 @@ int main() {
36
36
int out = 0;
37
37
38
38
// Send to channel
39
- in >> chan ;
39
+ chan << in ;
40
40
41
41
// Read from channel
42
- out << chan ;
42
+ chan >> out ;
43
43
44
44
assert (out == 1);
45
45
}
@@ -51,12 +51,10 @@ int main() {
51
51
int main () {
52
52
msd::channel<int> chan{2}; // buffered
53
53
54
- int in = 1;
55
-
56
54
// Send to channel
57
- in >> chan ;
58
- in >> chan ;
59
- in >> chan ; // blocking because capacity is 2 (and no one reads from channel)
55
+ chan << 1 ;
56
+ chan << 2 ;
57
+ chan << 3 ; // blocking because capacity is 2 (and no one reads from channel)
60
58
}
61
59
```
62
60
@@ -70,13 +68,13 @@ int main() {
70
68
int out = 0;
71
69
72
70
// Send to channel
73
- in >> chan ;
74
- in >> chan ;
71
+ chan << in ;
72
+ chan << in ;
75
73
76
74
// Read from channel
77
- out << chan ;
78
- out << chan ;
79
- out << chan ; // blocking because channel is empty (and no one writes on it)
75
+ chan >> out ;
76
+ chan >> out ;
77
+ chan >> out ; // blocking because channel is empty (and no one writes on it)
80
78
}
81
79
```
82
80
@@ -89,12 +87,11 @@ int main() {
89
87
msd::channel<int> chan;
90
88
91
89
int in1 = 1;
92
- in1 >> chan;
93
-
94
90
int in2 = 2;
95
- in2 >> chan;
96
91
97
- for (const auto out : chan) { // blocking: forever waiting for channel items
92
+ chan << in1 << in2;
93
+
94
+ for (const auto out : chan) { // blocking: forever waiting for channel items
98
95
std::cout << out << '\n';
99
96
}
100
97
}
0 commit comments