Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jeremyletang/tunnel
simple channel communication in c++
https://github.com/jeremyletang/tunnel
Last synced: 25 days ago
JSON representation
simple channel communication in c++
- Host: GitHub
- URL: https://github.com/jeremyletang/tunnel
- Owner: jeremyletang
- License: mit
- Created: 2015-02-22T14:11:04.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2015-03-07T07:20:18.000Z (over 9 years ago)
- Last Synced: 2023-07-31T14:58:49.419Z (over 1 year ago)
- Language: C++
- Size: 164 KB
- Stars: 4
- Watchers: 3
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# tunnel [![Build Status](https://travis-ci.org/jeremyletang/tunnel.svg?branch=master)](https://travis-ci.org/jeremyletang/tunnel)
Simple and lock-free channel communication in c++14
The API is based on the rust channel system for communication between threads.
The library use internally an mpsc queue to store message between channels and port
in a lock-free way.The library should build with clang (-std=c++1y) and gcc (-std=gnu++1y).
## A simple parallel example
```c++
#include
#include
#includeint main() {
// instanciate a new tunnel
auto comm = tunnel::make();
// get the channel
auto chan = std::move(std::get<0>(comm));
// get the port
auto port = std::move(std::get<1>(comm));// launch a thread and capture the port
auto t = std::thread([&]() {
auto p = std::move(port);
std::cout << p.recv().value << std::endl;
});// let the port waiting for data
std::this_thread::sleep_for(std::chrono::seconds(2));// send some data in the tunnel
chan.send(std::move("hello world from main thread !"));// wait for the thread exit
t.join();return 0;
}
```## Use tunnel
To use tunnel you need a c++14 compiler and cmake if you want to build the example
First you need to clone the repository and the submodule (mpsc_queue):
```shell
> git clone [email protected]:jeremyletang/tunnel.git --recursive
```You can build the examples using cmake
```
> cd tests && mkdir build && cd build && cmake .. && make
```then the examples are in the folder `/tests/build/target`.