Skip to content
This repository has been archived by the owner on Apr 15, 2020. It is now read-only.

Commit

Permalink
Add example for boost.fiber
Browse files Browse the repository at this point in the history
  • Loading branch information
gumb0 committed Jan 12, 2018
1 parent efbeba4 commit 980993c
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
16 changes: 16 additions & 0 deletions examples/Boost-fiber/CMakeLists.txt
@@ -0,0 +1,16 @@
# Copyright (c) 2013, Ruslan Baratov
# All rights reserved.

cmake_minimum_required(VERSION 3.0)

# Emulate HunterGate:
# * https://github.com/hunter-packages/gate
include("../common.cmake")

project(download-boost)

hunter_add_package(Boost COMPONENTS context fiber)
find_package(Boost CONFIG REQUIRED context fiber)

add_executable(foo foo.cpp)
target_link_libraries(foo PUBLIC Boost::context Boost::fiber)
22 changes: 22 additions & 0 deletions examples/Boost-fiber/foo.cpp
@@ -0,0 +1,22 @@
#include <boost/fiber/fiber.hpp>
#include <boost/fiber/future.hpp>
#include <boost/fiber/future/packaged_task.hpp>


int calculate_the_answer_to_life_the_universe_and_everything()
{
return 42;
}

int main() {
boost::fibers::packaged_task<int()> pt(calculate_the_answer_to_life_the_universe_and_everything);
boost::fibers::future<int> fi=pt.get_future();

boost::fibers::fiber task(boost::move(pt)); // launch task on a thread

fi.wait(); // wait for it to finish

assert(fi.valid());
assert(!fi.get_exception_ptr());
assert(fi.get()==42);
}

0 comments on commit 980993c

Please sign in to comment.