Martin Nilsson (Coppermist) @ Pike (-) developers forum wrote:
I have very bad experiences with MutexKeys being held for way too long and causing deadlocks (and I have a *lot* of experience on deadlocks in the pgsql driver).
Immediate destruct was added 1998. That doesn't mean it is bug free, but for such trivial use case as here I would be surprised if it was not, since it is used a lot in Roxen Webserver.
Well, maybe that is true at the end of a function in current Pike. Nonetheless: a. It does not hold true for other blocks besides functions. b. It is sensitive to tail call optimisation. c. Assigning 0 explicitly to MutexKeys everywhere makes it very explicit when it unlocks and makes it immune to code relocation. d. When I assign 0 to such a variable, and the Pike compiler sees that, is it then not possible for the optimiser to recognise that the assignment is redundant because we are about to leave functionscope anyway and then optimise the assignment away?
In the same veign, can the Pike optimiser not recognise this:
if (err) { Promise p = promise; // Cache it, to cover a failure race if (p) p->failure(err); }
And then just fetch the value of promise once, and then use it twice without us having to explicitly convert the code into:
if (err && promise) promise->failure(err);
?