ChimeraTK-cppext
01.05.02
Loading...
Searching...
No Matches
example.cc
Go to the documentation of this file.
1
// SPDX-FileCopyrightText: Deutsches Elektronen-Synchrotron DESY, MSK, ChimeraTK Project <chimeratk-support@desy.de>
2
// SPDX-License-Identifier: LGPL-3.0-or-later
3
/**********************************************************************************************************************
4
*
5
* VERY IMPORTANT NOTE!
6
*
7
* Whenever this file is changed, please update the example in the README.md
8
*file as well!
9
*
10
*********************************************************************************************************************/
11
12
#include <
future_queue.hpp
>
13
14
#include <iostream>
15
#include <thread>
16
#include <unistd.h>
17
18
// define future_queue of doubles with a length of 5
19
static
cppext::future_queue<double>
myQueue(5);
20
21
// define function sending data in a separate thread
22
void
senderThread
() {
23
for
(
size_t
i = 0; i < 10; ++i) {
24
usleep(100000);
// wait 0.1 second
25
myQueue.push(i * 3.14);
26
}
27
}
28
29
int
main
() {
30
// launch sender thread
31
std::thread myThread(&
senderThread
);
32
33
// receive 10 values and print them
34
for
(
size_t
i = 0; i < 10; ++i) {
35
double
value;
36
myQueue.pop_wait(value);
// wait until new data has arrived
37
std::cout << value << std::endl;
38
}
39
40
myThread.join();
41
return
0;
42
}
cppext::final_act
Definition
finally.hpp:13
senderThread
void senderThread()
Definition
example.cc:22
main
int main()
Definition
example.cc:29
future_queue.hpp
sources
ChimeraTK-cppext
tests
example.cc
Generated by
1.9.8