Niall Douglas wrote:
In my implementation, if you never call promise.get_future() you never get synchronisation.
That's an interesting use case. When does it occur?
The constexpr folding has the compiler elide all that.
I suspect that what you call "constexpr folding" has nothing to do with constexpr, it's just inlining and ordinary non-constexpr optimization. KAI C++ was famous for doing such folding miracles decades ago.
Also if you call promise.set_value() before promise.get_future(), you never get synchronisation as futures are single shot.
Another interesting case for which I've trouble imagining a practical use. :-)
I took a very simple synchronisation solution - a spinlock in both promise and future. Both are locked before any changes happen in either, if synchronisation has been switched on.
Not quite sure how this would work. Seems to me that future and promise both first need to take their spinlock and then the other's, which creates the potential for deadlock. But I may be missing something.