Use relaxed memory order for atomic counters

This commit is contained in:
Antonio SJ Musumeci 2023-08-21 13:33:58 -05:00
parent b6d3c34d3f
commit 0ed03a1535
4 changed files with 12 additions and 135 deletions

View file

@ -72,7 +72,7 @@ public:
void
enqueue_work(F&& f_)
{
auto i = _index++;
auto i = _index.fetch_add(1,std::memory_order_relaxed);
for(std::size_t n = 0; n < (_count * K); ++n)
{
@ -91,10 +91,11 @@ public:
using TaskReturnType = typename std::result_of<F()>::type;
using Promise = std::promise<TaskReturnType>;
auto i = _index++;
auto i = _index.fetch_add(1,std::memory_order_relaxed);
auto promise = std::make_shared<Promise>();
auto future = promise->get_future();
auto work = [=]() {
auto work = [=]()
{
auto rv = f_();
promise->set_value(rv);
};