Skip to content

Comment on In the C++ bag of tricks: scoped locksparent

Comments

Wait... if it's identical, how can it be safe against exceptions? `process2` isn't.

In addition to twoodfin's answer, I will point out that even if the code could throw, the code for the function would still be identical for when a throw did not occur (as in, we would see identical output with the addition of some code that would seemingly never be used or executed), on "good architectures", due to zero-cost exceptions (which only incur overhead during unwind; if no exception is thrown the code executed is exactly identical to if exceptions were not possible).

gcc can statically determine that incrementing f.var will not throw.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.