0

What I want to achieve: Having a set of unordered numbers, I would like to atomically select a random (or first, or whatever) element and remove from the set in the same operation.

Currently, I have:

std::list<int> pool = {1, 2, 3, ...};
int handle = pool.front();
pool.pop_front();

However, this does not ensure atomicity! I had hoped something like this existed:

std::list<int> pool = {1, 2, 3, ...};
int handle = pool.pop_front();

How do I achieve this?

casparjespersen
  • 3,460
  • 5
  • 38
  • 63

0 Answers0