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
19static cppext::future_queue<double> myQueue(5);
20
21// define function sending data in a separate thread
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
29int 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}
void senderThread()
Definition example.cc:22
int main()
Definition example.cc:29