Pure functions in D
Denis Koroskin
2korden at gmail.com
Wed Sep 24 02:49:44 PDT 2008
On Wed, 24 Sep 2008 08:25:59 +0400, Steven Schveighoffer
<schveiguy at yahoo.com> wrote:
> "Bruno Medeiros" wrote
>> Steven Schveighoffer wrote:
>>> Another possibility is that pure functions that accept mutable
>>> parameters
>>> can only be called from other pure functions, therefore you are
>>> guaranteed that the data is not being used in any other thread.
>>>
>>
[snip]
>
> I agree with you, partially pure functions can be called from pure
> functions
> with limited optimization. But if you allow foo to be called from an
> unpure
> function you could have this problem:
>
> int func2()
> {
> static int a = 1;
> foo(&a);
> }
>
> Now, if 2 threads are calling func2, you have race conditions and
> threading
> issues in foo, which seems to be a major concern that W/A were trying to
> address. And I hope they do address it, it was the one huge benefit I
> saw
> from pure functions.
>
> -Steve
>
>
No race conditions if "a" is unshared and Walter mentioned that pure
functions allowed thread-local mutable arguments only.
More information about the Digitalmars-d
mailing list