Issue 13930 - std.concurrency can't send immutable AA to another thread
Summary: std.concurrency can't send immutable AA to another thread
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: All All
: P1 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-01-04 02:44 UTC by Martin Nowak
Modified: 2020-10-10 23:23 UTC (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Martin Nowak 2015-01-04 02:44:08 UTC
cat > bug.d << CODE
import std.concurrency;

void main()
{
    immutable aa = ["0":0];
    thisTid.send(aa);
}
CODE

dmd -c bug

----

Trying to send an immutable associative array to another thread fails with this error messsage. Looks like a problem with copying in Variant or so.
Hash tables are basic types so this should be supported.

----
/usr/include/dmd/phobos/std/variant.d(621): Error: template instance std.variant.VariantN!32LU.VariantN.handler!(immutable(int[string])) error instantiating
/usr/include/dmd/phobos/std/variant.d(571):        instantiated from here: opAssign!(immutable(int[string]))
/usr/include/dmd/phobos/std/concurrency.d(109):        instantiated from here: __ctor!(immutable(int[string]))
/usr/include/dmd/phobos/std/concurrency.d(588):        instantiated from here: __ctor!(immutable(int[string]))
/usr/include/dmd/phobos/std/concurrency.d(578):        instantiated from here: _send!(immutable(int[string]))
/usr/include/dmd/phobos/std/concurrency.d(556):        instantiated from here: _send!(immutable(int[string]))
bug.d(6):        instantiated from here: send!(immutable(int[string]))
----
Comment 1 Martin Nowak 2015-01-05 21:37:26 UTC
Receiving immutable AAs doesn't work either.

cat > bug.d << CODE
import std.concurrency;

void main()
{
    auto aa = receiveOnly!(immutable string[string]);
}
CODE

dmd -c bug

DPL/dmd/src/../../phobos/std/concurrency.d(760): Error: cannot modify immutable expression ret.__expand_field_0
bug.d(5): Error: template instance std.concurrency.receiveOnly!(immutable(string[string])) error instantiating
Comment 2 JR 2016-12-25 12:33:09 UTC
Is there any easy workaround? Shared AAs can't be sent either[1].

[1]: http://melpon.org/wandbox/permlink/hoZTHJGgnWrnjxzw
Comment 3 Tomoya Tanjo 2020-10-08 15:15:35 UTC
I guess this issue contains two distinct problems.

The example in the first comment is about the problem of the `send` function.
I guess it was already solved by issue 21296 because the following test works without errors (I used phobos commit:f85ca8db in which issue 21296 was fixed):

```
@system unittest
{
    immutable aa = ["0":0];
    thisTid.send(aa);    
}
```


The example in the second comment is about the problem of the `receiveOnly` function (same as issue 19345).
This problem only happens with `receiveOnly` but does not happen with other `receive` family such as `receive` and `receiveTimeout`.
I confirmed the following tests work without errors (I used phobos commit:f85ca8db):

```
@system unittest
{
    immutable aa = ["0":0];
    thisTid.send(aa);
    receive((immutable int[string] val) {});
}

@system unittest
{
    immutable aa = ["0":0];
    thisTid.send(aa);
    receiveTimeout(10.seconds, (immutable int[string] val) {});
}
```

Note: I did not test the case of shared.
Comment 4 Dlang Bot 2020-10-09 15:15:04 UTC
@tom-tan created dlang/phobos pull request #7655 "Fix `receiveOnly` for non-assignable types (issue 13930, issue 19345)" mentioning this issue:

- Fix receiveOnly for non-assignable types
  - Fix issue 13930 - std.concurrency can't send immutable AA to another thread
  - Fix issue 19345 - std.concurrency does not work with structs of const value type

https://github.com/dlang/phobos/pull/7655
Comment 5 Dlang Bot 2020-10-10 02:09:24 UTC
dlang/phobos pull request #7655 "Fix issue 13930, 19345 - Fix `receiveOnly` for non-assignable types " was merged into master:

- d86c1f605995b423dd1a467b2c1c530dc52adb1e by Tomoya Tanjo:
  Fix issue 13930, 19345 - Fix receiveOnly for non-assignable types

https://github.com/dlang/phobos/pull/7655
Comment 6 Dlang Bot 2020-10-10 23:23:26 UTC
dlang/phobos pull request #7657 "Revert "Fix issue 13930, 19345 - Fix `receiveOnly` for non-assignable types "" was merged into master:

- 756242350896019ffc7a7cbe05e838538a559f5a by Mathias LANG:
  Revert "Fix issue 13930, 19345 - Fix receiveOnly for non-assignable types"
  
  This reverts commit 4f4fef19400ff85eb4699d569b02b21299b254cc.

https://github.com/dlang/phobos/pull/7657