Skip to content

Commit cf7b478

Browse files
authored
Added a paper on task issues and some code changes coming out of that
Issues
2 parents 774fc3b + ee6dd8b commit cf7b478

17 files changed

+1626
-43
lines changed

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ option(
1717
"Enable building tests and test infrastructure. Default: ON. Values: { ON, OFF }."
1818
${PROJECT_IS_TOP_LEVEL}
1919
)
20+
#set(BEMAN_TASK_BUILD_TESTS FALSE)
2021

2122
# [CMAKE.SKIP_EXAMPLES]
2223
option(

Makefile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#-dk: note to self: PATH=/opt/llvm-19.1.6/bin:$PATH LDFLAGS=-fuse-ld=lld
22

3-
.PHONY: config test default compile clean distclean doc format tidy
3+
.PHONY: config test default compile clean distclean doc html pdf format tidy
44

55
BUILDDIR = build
6-
PRESET = gcc-debug
6+
PRESET = gcc-release
77
UNAME = $(shell uname -s)
88
ifeq ($(UNAME),Darwin)
9-
PRESET = appleclang-debug
9+
PRESET = appleclang-release
1010
endif
1111
BUILD = $(BUILDDIR)/$(PRESET)
1212

@@ -15,6 +15,9 @@ default: compile
1515
doc:
1616
cd docs; $(MAKE)
1717

18+
pdf html:
19+
cd docs; $(MAKE) doc-$@
20+
1821
compile:
1922
CMAKE_EXPORT_COMPILE_COMMANDS=1 \
2023
cmake \

docs/Makefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
.PHONY: default doc
1+
.PHONY: default doc doc-html doc-pdf
22

33
default: doc
44

5-
doc: P3552-task.html
5+
doc: doc-html
6+
7+
doc-html: P3552-task.html P3796-task-issues.html
8+
9+
doc-pdf: P3552-task.pdf P3796-task-issues.pdf
610

711
wg21/Makefile:
812
git clone https://github.com/mpark/wg21.git

docs/P3796-task-issues.md

Lines changed: 1126 additions & 0 deletions
Large diffs are not rendered by default.

docs/issues-overview.md

Lines changed: 274 additions & 0 deletions
Large diffs are not rendered by default.

examples/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
22

3-
set(ALL_EXAMPLES co_await-task)
43
set(ALL_EXAMPLES
4+
customize
5+
issue-symmetric-transfer
56
affinity
67
alloc
78
c++now-affinity
@@ -23,12 +24,17 @@ set(ALL_EXAMPLES
2324
friendly
2425
hello
2526
into_optional
27+
issue-affine_on
28+
issue-frame-allocator
29+
issue-start-reschedules
2630
loop
2731
query
2832
result_example
2933
stop
3034
task_scheduler
3135
)
36+
set(xALL_EXAMPLES issue-symmetric-transfer)
37+
set(xALL_EXAMPLES customize)
3238

3339
message("Examples to be built: ${ALL_EXAMPLES}")
3440

examples/customize.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// examples/customize.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/execution/execution.hpp>
5+
#include <beman/task/task.hpp>
6+
#include "demo-thread_pool.hpp"
7+
#include <iostream>
8+
#include <utility>
9+
#include <cassert>
10+
11+
namespace ex = beman::execution;
12+
13+
namespace {
14+
struct empty {};
15+
} // namespace
16+
17+
int main() {
18+
#if 0
19+
auto task = []()->ex::task<void, empty> { co_return; }();
20+
static_assert(ex::sender<decltype(task)>);
21+
auto env = ex::get_env(task);
22+
static_assert(std::same_as<decltype(task)::env, decltype(env)>);
23+
auto dom = ex::get_domain(env);
24+
static_assert(std::same_as<decltype(task)::domain, decltype(dom)>);
25+
auto edom = ex::detail::get_domain_early(task);
26+
static_assert(std::same_as<decltype(task)::domain, decltype(edom)>);
27+
std::cout << "---\n";
28+
transform_sender(edom, ex::detail::make_sender(ex::affine_on, ex::inline_scheduler{}, std::move(task)));
29+
std::cout << "---\n";
30+
auto affine = ex::affine_on(std::move(task), ex::inline_scheduler{});
31+
#endif
32+
}

examples/issue-affine_on.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// examples/issue-affine_on.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/execution/task.hpp>
5+
#include <beman/execution/execution.hpp>
6+
#include <iostream>
7+
8+
namespace ex = beman::execution;
9+
10+
template <ex::sender Sender>
11+
ex::task<> test(Sender&& sender) {
12+
co_await std::move(sender);
13+
}
14+
15+
int main() {
16+
ex::sync_wait(test(ex::just()));
17+
ex::sync_wait(test(ex::read_env(ex::get_scheduler) |
18+
ex::let_value([](auto sched) { return ex::starts_on(sched, ex::just()); })));
19+
}

examples/issue-frame-allocator.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// examples/issue-frame-allocator.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/execution/task.hpp>
5+
#include <beman/execution/execution.hpp>
6+
#include <iostream>
7+
#include <functional>
8+
#include <memory_resource>
9+
10+
namespace ex = beman::execution;
11+
12+
template <typename Env>
13+
ex::task<int, Env> test(int i, auto&&...) {
14+
co_return co_await ex::just(i);
15+
}
16+
struct default_env {};
17+
struct allocator_env {
18+
using allocator_type = std::pmr::polymorphic_allocator<>;
19+
};
20+
21+
int main() {
22+
ex::sync_wait(test<default_env>(17)); // OK: no allocator
23+
ex::sync_wait(test<default_env>(17, std::allocator_arg, std::allocator<int>())); // OK: allocator is convertible
24+
// ex::sync_wait(test<default_env>(17, std::allocator_arg, std::pmr::polymorphic_allocator<>())); // error
25+
ex::sync_wait(test<allocator_env>(17, std::allocator_arg, std::pmr::polymorphic_allocator<>())); // OK but unusual
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// examples/issue-start-reschedules.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/execution/task.hpp>
5+
#include <beman/execution/execution.hpp>
6+
#include "demo-thread_pool.hpp"
7+
#include <iostream>
8+
#include <thread>
9+
10+
namespace ex = beman::execution;
11+
12+
ex::task<> test(auto sched) {
13+
std::cout << "init =" << std::this_thread::get_id() << "\n";
14+
co_await ex::starts_on(sched, ex::just());
15+
std::cout << "final=" << std::this_thread::get_id() << "\n";
16+
}
17+
18+
int main() {
19+
demo::thread_pool pool1;
20+
demo::thread_pool pool2;
21+
std::cout << "main =" << std::this_thread::get_id() << "\n";
22+
ex::sync_wait(ex::schedule(pool1.get_scheduler()) |
23+
ex::then([] { std::cout << "pool1=" << std::this_thread::get_id() << "\n"; }));
24+
ex::sync_wait(ex::schedule(pool2.get_scheduler()) |
25+
ex::then([] { std::cout << "pool2=" << std::this_thread::get_id() << "\n"; }));
26+
std::cout << "--- use 1 ---\n";
27+
ex::sync_wait(test(pool2.get_scheduler()));
28+
std::cout << "--- use 2 ---\n";
29+
ex::sync_wait(ex::starts_on(pool1.get_scheduler(), test(pool2.get_scheduler())));
30+
}

0 commit comments

Comments
 (0)