This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
38 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |