Disallow side effects in assert

Marco Leise Marco.Leise at gmx.de
Mon Feb 3 11:30:42 PST 2014


Am Mon, 03 Feb 2014 10:33:11 -0800
schrieb Brad Roberts <braddr at puremagic.com>:

> I have one semi-large code base where I validate the locking semantics 
> by adding assert(!lock.try_acquire)'s.  That's clearly a side effect, 
> but also clearly should never have one if the code is correct.

Damn those gotchas. Basically lock.try_acquire is pure when it
returns false, and if not, the program is terminated anyways so
it doesn't make a difference.

I also noticed that contracts don't work at all with shared
objects. Where you synchronize around a mutex inside a method
you have to move all checks into the critical section.
Yeah, its obvious, but when you turn a non-thread-safe
structure into a thread-safe one and have to delete all
in-out-blocks it hurts a bit. :)

-- 
Marco



More information about the Digitalmars-d mailing list