August 09, 2015
On Saturday, 8 August 2015 at 06:24:30 UTC, sigod wrote:
> Use negative value for `receiveTimeout`. http://stackoverflow.com/q/31616339/944911

On Saturday, 8 August 2015 at 13:34:24 UTC, Chris wrote:
> Note aside: if you only import what you need (say `import std.concurrency : receiveTimeout; std.datetime : msecs`), you can reduce the size of the executable considerably as your program grows.

Thanks for the tips!

August 09, 2015
On Saturday, 8 August 2015 at 05:14:20 UTC, Meta wrote:
> I'm not completely sure that it's bad in this case, but you really shouldn't be casting away immutable. It's undefined behaviour in D.

Afaict it is the best way to do what I'm trying to do, and since the data is mutable and cast to immutable with assumeUnique, casting it back to mutable shouldn't be a problem. Technically casting away immutable might be undefined behaviour and it might be an ugly hack, but I don't see a more idiomatic solution.

August 09, 2015
On Sunday, 9 August 2015 at 17:43:59 UTC, 岩倉 澪 wrote:
> Afaict it is the best way to do what I'm trying to do, and since the data is mutable and cast to immutable with assumeUnique, casting it back to mutable shouldn't be a problem. Technically casting away immutable might be undefined behaviour and it might be an ugly hack, but I don't see a more idiomatic solution.

I think casting to shared and back would be better.

Unfortunately, it looks like std.concurrency.send doesn't like shared arrays. I filed an issue: https://issues.dlang.org/show_bug.cgi?id=14893
August 09, 2015
On Sunday, 9 August 2015 at 21:06:10 UTC, anonymous wrote:
> On Sunday, 9 August 2015 at 17:43:59 UTC, 岩倉 澪 wrote:
>> Afaict it is the best way to do what I'm trying to do, and since the data is mutable and cast to immutable with assumeUnique, casting it back to mutable shouldn't be a problem. Technically casting away immutable might be undefined behaviour and it might be an ugly hack, but I don't see a more idiomatic solution.
>
> I think casting to shared and back would be better.
>
> Unfortunately, it looks like std.concurrency.send doesn't like shared arrays. I filed an issue: https://issues.dlang.org/show_bug.cgi?id=14893

I agree! I initially tried to cast to shared and back, but when I encountered that compiler error I decided to go with immutable. I assumed that there was a good reason it didn't work, rather than a deficiency in the language. Hopefully the issue can be resolved, leading to a nicer solution. :)
August 10, 2015
There's indeed a good reason: Variant is a kitchen sink wrapper and tries to declare questionable code for shared type, and compiler catches that. Quite an impressive example of shared type qualifier in action, even though Variant uses a lot of casting so there's not a lot of type system at work there.
August 10, 2015
On Saturday, 8 August 2015 at 06:24:30 UTC, sigod wrote:
> Use negative value for `receiveTimeout`. http://stackoverflow.com/q/31616339/944911

actually this no longer appears to be true?
Passing -1.msecs as the duration gives me an assertion failure:

>core.exception.AssertError@std/concurrency.d(1902): Assertion failure

Took a look in phobos and it appears to be from this line:
https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1904

If you look at the implementation of receiveTimeout, you'll see that it no longer has these lines from the stack overflow answer:

    if( period.isNegative || !m_putMsg.wait( period ) )
    return false;

https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L824
August 10, 2015
On Monday, 10 August 2015 at 22:21:18 UTC, 岩倉 澪 wrote:
> On Saturday, 8 August 2015 at 06:24:30 UTC, sigod wrote:
>> Use negative value for `receiveTimeout`. http://stackoverflow.com/q/31616339/944911
>
> actually this no longer appears to be true?
> Passing -1.msecs as the duration gives me an assertion failure:
>
>>core.exception.AssertError@std/concurrency.d(1902): Assertion failure
>
> Took a look in phobos and it appears to be from this line:
> https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1904
>
> If you look at the implementation of receiveTimeout, you'll see that it no longer has these lines from the stack overflow answer:
>
>     if( period.isNegative || !m_putMsg.wait( period ) )
>     return false;
>
> https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L824

That's weird. Especially when latest commit is mine: https://github.com/D-Programming-Language/phobos/commit/c8048fa48832a97f033b748f5e6b8edde3f2ae29
August 10, 2015
On Monday, 10 August 2015 at 22:21:18 UTC, 岩倉 澪 wrote:
> On Saturday, 8 August 2015 at 06:24:30 UTC, sigod wrote:
>> Use negative value for `receiveTimeout`. http://stackoverflow.com/q/31616339/944911
>
> actually this no longer appears to be true?
> Passing -1.msecs as the duration gives me an assertion failure:
>
>>core.exception.AssertError@std/concurrency.d(1902): Assertion failure
>
> Took a look in phobos and it appears to be from this line:
> https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1904

It should be this line: https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1910

> If you look at the implementation of receiveTimeout, you'll see that it no longer has these lines from the stack overflow answer:
>
>     if( period.isNegative || !m_putMsg.wait( period ) )
>     return false;
>
> https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L824

This lines still there: https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L2081

I'll remove mentioned assert.
August 10, 2015
On Monday, 10 August 2015 at 22:21:18 UTC, 岩倉 澪 wrote:
> On Saturday, 8 August 2015 at 06:24:30 UTC, sigod wrote:
>> Use negative value for `receiveTimeout`. http://stackoverflow.com/q/31616339/944911
>
> actually this no longer appears to be true?
> Passing -1.msecs as the duration gives me an assertion failure:
>
>>core.exception.AssertError@std/concurrency.d(1902): Assertion failure
>
> Took a look in phobos and it appears to be from this line:
> https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1904

It looks like you're trying to use `receiveTimeout` like this:

    bool value;
    receiveTimeout(-1.msecs, value);

But you must use it like this:

    bool value;
    receiveTimeout(-1.msecs, (bool b) { value = b; });

See [`receive`][0] for example.

[0]: http://dlang.org/phobos/std_concurrency.html#.receive
August 10, 2015
On Monday, 10 August 2015 at 22:31:33 UTC, sigod wrote:
> On Monday, 10 August 2015 at 22:21:18 UTC, 岩倉 澪 wrote:
>> [...]
>
> It should be this line: https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L1910
>
>> [...]
>
> This lines still there: https://github.com/D-Programming-Language/phobos/blob/master/std/concurrency.d#L2081
>
> I'll remove mentioned assert.

https://github.com/D-Programming-Language/phobos/pull/3545