Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.concurrency send() fails with structs over 32 bytes #9612

Open
dlangBugzillaToGithub opened this issue Jul 31, 2013 · 4 comments
Open

std.concurrency send() fails with structs over 32 bytes #9612

dlangBugzillaToGithub opened this issue Jul 31, 2013 · 4 comments

Comments

@dlangBugzillaToGithub
Copy link

david (@davideagen) reported this on 2013-07-31T21:44:11Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=10740

CC List

  • johannespfau (@jpf91)
  • mk
  • secondaryAccount
  • zorael

Description

Using 2.063.2 and 2.064-devel-333c6dd:

import std.concurrency : receiveOnly, send, thisTid;
import std.exception : assumeUnique;
import std.variant;

struct JustRight
{
    byte[32] j;
}

struct TooBig
{
    byte[33] t;
}

void main()
{
    JustRight[1] jArray;
    TooBig[1]    tArray;

    Variant vj = jArray[];
    Variant vt = tArray[];

    thisTid.send(vj);
    thisTid.send(vt);

    thisTid.send(assumeUnique(jArray[]));
    //thisTid.send(assumeUnique(tArray[])); // Fails to compile

    auto received = receiveOnly!((JustRight)[]);
}

If the send of tArray is commented out the compilation fails with:

src/phobos/std/variant.d(558): Error: cannot modify immutable expression *p

So, 32-byte structs can be sent (as arrays) using send or if you first wrap it in an Variant object. Greater than 32-byte structs can be sent ONLY if they are pre-wrapped in a Variant. The size of the data shouldn't limit it from being sent using send().
@dlangBugzillaToGithub
Copy link
Author

david commented on 2013-08-01T04:33:47Z

Should have said:

"If the send of tArray is uncommented the compilation fails with:"

@dlangBugzillaToGithub
Copy link
Author

johannespfau (@jpf91) commented on 2013-08-24T06:08:34Z

There recently was a bug report for GDC/ARM regarding this. As variants max size is determined by creal which is only 16 bytes on most non-x86 architectures this error already happens with structs > 16 bytes on these architectures.

Another test case with different error message:
---------
struct Big
{
	int[10] a;
}

import std.concurrency, std.variant, core.thread;

void loop()
{
	while(true)
	{
		Thread.sleep(seconds(10));
	}
}

void main()
{
	auto x = spawn(&loop);
	x.send(Big());
}
---------
http://dpaste.dzfl.pl/f103dbac

core.exception.AssertError@/opt/compilers/dmd2/include/std/variant.d(280): target must be non-null

@dlangBugzillaToGithub
Copy link
Author

mk commented on 2014-01-07T18:45:32Z

Comment #2 is bug 9122. Comment #0 still open (the limit is 24 bytes for me).

@dlangBugzillaToGithub
Copy link
Author

secondaryAccount commented on 2015-09-02T18:43:20Z

still valid with dmd 2.068, but the location of the error changed:
 dmd/phobos/std/variant.d(634): Error: cannot modify immutable expression *p
 dmd/phobos/std/variant.d(420): Error: template instance std.variant.VariantN!32LU.VariantN.opAssign!(immutable(TooBig)) error instantiating
[...]

@thewilsonator thewilsonator removed P2 OS:Linux Issues specific to Linux Arch:x86_64 Issues specific to x86_64 labels Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants