Hey! Nice!
line 42 I think you forgot promise.set_value(); #4 in https://en.cppreference.com/w/cpp/thread/promise/set_value.html
in line 12 and 13 you are doing two loads, you should be able to do that in one load (not sure this is faster in any scenario, should probably profile it)
std::unique_lock lock{m_mutex};
std::optional<bool> should_work = std::nullopt;
m_condvar.wait(lock, [this, &should_work] mutable {
if (!m_tasks.empty()) return true;
const bool tmp = m_should_work.load(std::memory_order_acquire);
if (!tmp) {
should_work = tmp;
return true;
}
return false;
});
if (!should_work.or_else([this] {return m_should_work.load(std::memory_order_acquire);})) return;
in line 57 wrap the invoke with static_cast<void>(std::invoke(function, args...)); or use [[maybe_unused]], don't think the compiler cares about comments
also, is it not better to forward the args as well into invoke?
and I guess follow the rule of 5 or 6 I dunno, just default move constructor/assignment
super minor as it's about style: lambdas without args do not need parenthesis