33 lines
590 B
C++
33 lines
590 B
C++
#include <alsk/alsk.h>
|
|
|
|
#include <future>
|
|
|
|
using namespace alsk::arg;
|
|
|
|
int main() {
|
|
alsk::exec::ExecutorState<alsk::exec::DynamicPool<void>> state;
|
|
|
|
state.config(4);
|
|
|
|
constexpr int n = 40;
|
|
std::array<std::future<void>, n> futures;
|
|
|
|
std::puts("begin");
|
|
|
|
for(int i = 0; i < n; ++i) {
|
|
futures[i] = state.run([i] { for(int x = 0; x < 20'000'000+5'000'000*i; ++x); });
|
|
}
|
|
|
|
std::puts("wait");
|
|
|
|
std::promise<int> p;
|
|
std::future<int> f = state.run([] { return 42; }, p);
|
|
|
|
std::printf("with value: %d\n", f.get());
|
|
|
|
for(int i = 0; i < n; ++i)
|
|
futures[i].wait();
|
|
|
|
std::puts("end");
|
|
}
|