Non-obvious lifetime issue with std::promise and std::future
This question is very similar to a previous one here: race-condition in pthread_once()? It is essentially the same issue - the lifetime of a std::promise ending during a call to promise::set_value (ie: after the associated future has been flagged, but before pthread_once has executed) So I know that my usage has this issue, and that I therefore cannot use it in this way. However, I think this is non-obvious. (In the wise words of Scott Meyer: Make Interfaces Easy to Use Correctly and Hard to Use Incorrectly ) I present an exemplar below: I have a thread ( dispatcher ) which spins on a queue,