Most basic nothrow, pure, @safe functions?
Steven Schveighoffer
schveiguy at yahoo.com
Thu Mar 20 19:14:59 PDT 2014
On Thu, 20 Mar 2014 22:00:15 -0400, Walter Bright
<newshound2 at digitalmars.com> wrote:
> On 3/20/2014 6:40 PM, Steven Schveighoffer wrote:
>> How do they affect global state?
>
> Mutexes implicitly share state. It's the reason they exist. They can't
> be pure, because pure functions don't share state.
I view it differently. I feel like locking and unlocking a mutex is pure.
After calling lock, the same thing *always* happens. After unlocking, the
same thing *always* happens. It's a weird thing -- when you lock a mutex,
you own it after it's locked. It's no longer shared. It can be thought of
as pulling memory out of the heap to temporarily own, and then putting it
back, just like memory allocation (which is considered pure).
This is quite different from actual global state, which is accessed via
globals.
trylock I don't think should be pure. I'm not sure about read/write locks.
-Steve
More information about the Digitalmars-d
mailing list