Skip to content

Commit d722622

Browse files
authored
Fixes to futures (#505)
* Fixes to futures Fixed unnecessary copies of copyable result types when futures are used as rvalues. Propagating exceptions for move-only types are now scheduled on the executor (I'm not sure why they were not scheduled before). Added `copy()` algorithm to utility.hpp to explicitly copy objects. * Forwarding lambdas need to be mutable. * Filling in missing documentation and fixing some includes. * Adding unit test for utility.hpp * Taking my more refined implementation of copy from artemis
1 parent 9a75c3d commit d722622

File tree

10 files changed

+333
-273
lines changed

10 files changed

+333
-273
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
---
2+
layout: method
3+
title: canceled
4+
owner: sean-parent
5+
brief: Returns true if there are no longer any futures attached to the task.
6+
tags:
7+
- method
8+
defined_in_file: concurrency/future.hpp
9+
overloads:
10+
bool canceled() const:
11+
description: __OPTIONAL__
12+
return: __OPTIONAL__
13+
signature_with_names: bool canceled() const
14+
---

docs/libraries/utility.hpp/f_copy.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
layout: function
3+
title: copy
4+
owner: sean-parent
5+
brief: Returns a copy of the argument
6+
tags:
7+
- function
8+
defined_in_file: utility.hpp
9+
overloads:
10+
"template <typename T>\nT copy(const T &)":
11+
arguments:
12+
- description: __OPTIONAL__
13+
name: a
14+
type: const T &
15+
description: __OPTIONAL__
16+
return: __OPTIONAL__
17+
signature_with_names: "template <typename T>\nT copy(const T & a)"
18+
namespace:
19+
- stlab
20+
- v1
21+
---
22+
23+
Useful for functions that only take an rvalue reference or that have an explicit copy constructor.
24+
25+
Example:
26+
```cpp
27+
void f(vector<int>&&);
28+
//...
29+
vector<int> a = ...;
30+
f(copy(a)); // pass a copy
31+
f(move(a)); // sink a
32+
```

docs/tools/docker-tools/README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ If you don't already have docker installed, [install Docker](https://docs.docker
77

88
### Building the docker image
99

10-
To build the docker image, first update the VERSION variable below (please use semantic versioning). Add a [release note](#release-notes).
10+
To build the docker image, first, update the VERSION variable below (please use semantic versioning). Add a [release note](#release-notes).
1111

1212
```
1313
VERSION="1.0.1"
@@ -23,7 +23,7 @@ echo $RUBY_VERSION > ./docs/.ruby-version
2323
# build the base image, no-cache is used so the latest tools are installed
2424
docker build --build-arg RUBY_VERSION=$RUBY_VERSION --file ./docs/tools/docker-tools/Dockerfile \
2525
--target base --tag $VOLUME . \
26-
--no-cache
26+
--no-cache
2727
2828
# update the docs environment
2929
docker run --mount type=bind,source="$(pwd)",target=/mnt/host --tty --interactive $VOLUME bash
@@ -67,14 +67,14 @@ cd /mnt/host
6767

6868
## Run a local server for the site
6969

70-
Once the site has been prepared, you can run it to see how it looks. From the docker promt enter:
70+
Once the site has been prepared, you can run it to see how it looks. From the docker prompt enter:
7171

7272
```
7373
cd /mnt/host
7474
./docs/tools/docs/start.sh
7575
```
7676

77-
To view the site, open a browser to `http://localhost:3000`. The site will auto rebuild and refresh as files are changed.
77+
To view the site, open a browser to `http://localhost:3000`. The site will auto-rebuild and refresh as files are changed.
7878

7979
## Tips
8080

@@ -85,7 +85,7 @@ docker ps
8585
docker exec -it <container id> bash
8686
```
8787

88-
To test a local copy of the jekyll theme, edit the Gemfile and use:
88+
To test a local copy of the Jekyll theme, edit the Gemfile and use:
8989

9090
```
9191
docker run --mount type=bind,source="$(pwd)",target=/mnt/host \
@@ -96,5 +96,5 @@ docker run --mount type=bind,source="$(pwd)",target=/mnt/host \
9696

9797
### Release Notes
9898

99-
- 1.0.0 - Initial release for jekyll
100-
- 1.0.1 - Updating tool set
99+
- 1.0.0 - Initial release for Jekyll
100+
- 1.0.1 - Updating toolset

stlab/concurrency/await.hpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,24 @@
99
#ifndef STLAB_CONCURRENCY_AWAIT_HPP
1010
#define STLAB_CONCURRENCY_AWAIT_HPP
1111

12+
#include <stlab/config.hpp>
13+
1214
#include <chrono>
1315
#include <condition_variable>
1416
#include <exception>
1517
#include <mutex>
1618
#include <type_traits>
1719
#include <utility>
1820

19-
#include <stlab/concurrency/default_executor.hpp>
2021
#include <stlab/concurrency/future.hpp>
2122
#include <stlab/concurrency/immediate_executor.hpp>
2223
#include <stlab/concurrency/ready_future.hpp>
2324
#include <stlab/memory.hpp>
2425

26+
#if STLAB_TASK_SYSTEM(PORTABLE)
27+
#include <stlab/concurrency/default_executor.hpp>
28+
#endif
29+
2530
/**************************************************************************************************/
2631

2732
namespace stlab {
@@ -93,8 +98,8 @@ T await(future<T> x) {
9398
std::condition_variable condition;
9499
bool flag{false};
95100

96-
auto hold = std::move(x).recover(immediate_executor, [&](auto&& r) {
97-
x = std::forward<decltype(r)>(r);
101+
auto hold = std::move(x).recover(immediate_executor, [&](future<T>&& r) {
102+
x = std::move(r);
98103
{
99104
std::unique_lock<std::mutex> lock{m};
100105
flag = true;
@@ -201,8 +206,9 @@ template <class T>
201206
}
202207

203208
template <class T>
204-
[[deprecated("Use await_for instead.")]] auto blocking_get(
205-
future<T> x, const std::chrono::nanoseconds& timeout) -> decltype(x.get_try()) {
209+
[[deprecated("Use await_for instead.")]] auto blocking_get(future<T> x,
210+
const std::chrono::nanoseconds& timeout)
211+
-> decltype(x.get_try()) {
206212
return blocking_get_for(std::move(x), timeout).get_try();
207213
}
208214

0 commit comments

Comments
 (0)