25 May
2015
25 May
'15
11:58 p.m.
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.
You could fix that by preallocating a sufficiently big static array of spinlocks, then generating an index when creating the promise and using spinlock_[i] in both. Collisions are possible but harmless. This non-allocating implementation is an interesting argument in favor of the current "unique future", which I've long disliked. I prefer futures to be shared_futures. That may too be possible to implement without allocation, but it's kind of complicated.