Commit 4c626a86 by FritzFlorian

Add high level bindings for spawn/sync.

parent e2de954a
Pipeline #1425 failed with stages
in 31 seconds
...@@ -13,10 +13,10 @@ namespace pls { ...@@ -13,10 +13,10 @@ namespace pls {
// 'basic' for-join APIs // 'basic' for-join APIs
using internal::scheduling::scheduler; using internal::scheduling::scheduler;
template<typename Function> template<typename Function>
void spawn(Function &&function) { static void spawn(Function &&function) {
scheduler::spawn(std::forward<Function>(function)); scheduler::spawn(std::forward<Function>(function));
} }
void sync() { static void sync() {
scheduler::sync(); scheduler::sync();
} }
......
...@@ -7,6 +7,29 @@ ...@@ -7,6 +7,29 @@
constexpr int MAX_NUM_TASKS = 32; constexpr int MAX_NUM_TASKS = 32;
constexpr int MAX_STACK_SIZE = 1024 * 8; constexpr int MAX_STACK_SIZE = 1024 * 8;
TEST_CASE("spawn/sync invoke calls correctly", "[algorithms/invoke.h]") {
pls::scheduler scheduler{3, MAX_NUM_TASKS, MAX_STACK_SIZE};
std::atomic<int> num_run{0};
scheduler.perform_work([&] {
pls::spawn([&] {
num_run++;
while (num_run < 3);
});
pls::spawn([&] {
while (num_run < 1);
num_run++;
while (num_run < 3);
});
pls::spawn([&] {
while (num_run < 2);
num_run++;
});
pls::sync();
REQUIRE(num_run == 3);
});
}
TEST_CASE("parallel invoke calls correctly", "[algorithms/invoke.h]") { TEST_CASE("parallel invoke calls correctly", "[algorithms/invoke.h]") {
pls::scheduler scheduler{3, MAX_NUM_TASKS, MAX_STACK_SIZE}; pls::scheduler scheduler{3, MAX_NUM_TASKS, MAX_STACK_SIZE};
......
#include <catch.hpp> #include <catch.hpp>
#include <vector>
#include <atomic> #include <atomic>
#include "pls/internal/scheduling/traded_cas_field.h" #include "pls/internal/scheduling/traded_cas_field.h"
#include "pls/internal/scheduling/task.h"
#include "pls/internal/scheduling/external_trading_deque.h" #include "pls/internal/scheduling/external_trading_deque.h"
#include "pls/internal/scheduling/scheduler.h" #include "pls/pls.h"
using namespace pls::internal::scheduling; using namespace pls::internal::scheduling;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment