29template<
typename CONTEXT =
int>
36 for (
const CONTEXT& c : context) {
40 myThreads.emplace_back([
this, index, c] {
run(index, c); });
48 queue.setEnabled(
false);
55 template<
typename TaskT>
56 auto executeAsync(TaskT&& task,
int idx = -1) -> std::future<decltype(task(std::declval<CONTEXT>()))> {
65 auto result =
myQueues[(index + n) %
myQueues.size()].tryPush(task, success);
76 std::vector<std::future<void>> results;
77 for (
int n = 0; n != (int)
myQueues.size(); ++n) {
80 for (
auto& r : results) {
86 void run(
size_t queueIndex,
const CONTEXT& context) {
87 while (
myQueues[queueIndex].isEnabled()) {
89 if (
myQueues[queueIndex].waitAndPop(task)) {
96 while (
myQueues[queueIndex].isEnabled()) {
103 if (!task && !
myQueues[queueIndex].waitAndPop(task)) {
std::unique_ptr< TaskBase< C > > TaskPtrType
std::vector< TaskQueue< CONTEXT > > myQueues
auto executeAsync(TaskT &&task, int idx=-1) -> std::future< decltype(task(std::declval< CONTEXT >()))>
void workStealRun(size_t queueIndex, const CONTEXT &context)
std::vector< std::thread > myThreads
const size_t myTryoutCount
WorkStealingThreadPool(const bool workSteal, const std::vector< CONTEXT > &context)
void run(size_t queueIndex, const CONTEXT &context)
std::atomic< size_t > myQueueIndex
~WorkStealingThreadPool()