www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9122] New: std.concurrency send() fails with multiple arrays

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122

           Summary: std.concurrency send() fails with multiple arrays
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: john.loughran.colvin gmail.com



06:04:25 PST ---
import std.concurrency;
import std.stdio;

void foo() {
    bool running  = true;
    while(running) {
         receive(
        (immutable(double)[] a, immutable(double)[] b, int i) {
        writeln(a, b, i);
        },
        (OwnerTerminated e) {
        running = false;
        }
    );
    }
}

void main() {
    double[] a,b;
    a = [1.1];
    b = [2.2];
    int i= 3;

    auto tid = spawn(&foo);

    tid.send(a.idup, b.idup, i); 
}

I get: core.exception.AssertError  std/variant.d(277): target must be non-null

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Dec 07 2012
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122


David Eagen <david eagen.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |david eagen.com



This is probably related to issue 7069. 

The problem also occurs on structs like this:

import std.concurrency, std.exception, std.stdio;

struct Combined
{
  string str1;
  string str2;
  bool status;
}

void main() {
   auto tid = spawn(&worker);
   Combined c = Combined("one", "two", false);
   tid.send(c);
}

void worker() {
  for (bool running = true; running; ) 
  {
    receive(
        (Combined c) 
        { 
          writeln("Got ", c.str1, "\t", c.str2, "\t", c.status);
        },

    (OwnerTerminated unused)
    {
      running = false;
    }    
    );
  }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 03 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122


David Eagen <david eagen.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |major



Bumping importance. This issue makes it impossible for me to move to 2.061
because it breaks all my applications that use message passing for concurrency.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 03 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122


David Eagen <david eagen.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|major                       |regression


-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 05 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122


Martin Krejcirik <mk krej.cz> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mk krej.cz




("target must be non-null") when the size of a message (Combined.sizeof)
exceeds 24 bytes.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 31 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122


Zhenya Chapovsky <zheny list.ru> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |zheny list.ru



Is anyone working on this issue?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122


Tavi Cacina <octavian.cacina outlook.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |octavian.cacina outlook.com



11:45:43 PDT ---
I hit this bug too as I wanted to send a structure. Martin Krejcirik was right
about the size of the structure. As soon as the message to be sent exceeds 20
bytes (win32) it comes to the assert. I see that the problem is with the
default generated opAssign for the struct Message in std.concurrency. This
Message has a "Variant data" attribute that needs to be copied. 

I could reproduce the error like this: 
---
struct S { int p1, p2, p3, p4, p5, p6; }
Variant v1 = S();
Variant v2;
v2 = v1; // assert
---

The Variant is defined like:
alias VariantN!(maxSize!(creal, char[], void delegate())) Variant;
so it has already a fixed size. The constructor can cope with the bigger size
and will adjust, but the opAssign does not. I do not know if it is a bug that
the constructor allows it or that the opAssign does not. 

A possible fix would be to add an opAssign operator to the Message structure:

---
ref Message opAssign(Message rhs) 
{ 
    type = rhs.type;
    swap(data, rhs.data); 
    return this; 
} 
---

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 23 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122


Martin Nowak <code dawg.eu> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |code dawg.eu




 The Variant is defined like:
 alias VariantN!(maxSize!(creal, char[], void delegate())) Variant;
 so it has already a fixed size. The constructor can cope with the bigger size
 and will adjust, but the opAssign does not.
OpAssign moves the assigned value onto the heap so this is not the problem. https://github.com/D-Programming-Language/phobos/blob/c319b1578f28e00124d2f0c2a492790d01ca5159/std/variant.d#L545 Also the following code works correctly for me on 2.062. --- import std.variant, std.stdio; struct S { int p1, p2, p3, p4, p5, p6; } void main() { Variant v1 = S(1, 2, 3, 4, 5, 6); writeln(v1); Variant v2; writeln(v2); v2 = v1; // assert writeln(v2); } --- The bug seems to be in the handler for OpID.copyOut. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 14 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122


Tavi Cacina <octavian.cacina outlook.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |http://d.puremagic.com/issu
                   |                            |es/show_bug.cgi?id=10017



23:54:37 PDT ---

 
 Also the following code works correctly for me on 2.062.
yes, here I have a wrong sample, the structure size must exceed 32bytes. The S should be: struct S { int[9] s; } structure I also made a pull request for it ( https://github.com/D-Programming-Language/phobos/pull/1281 ) but David Nadlinger wants to fix the fact that these Variant assignments trigger a reallocation even if there already is a heap value (comments in pull). -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
May 14 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122




This is now resolved after the fix for 10017
(https://github.com/D-Programming-Language/phobos/commit/5ddf3bc19a240b77255c9583aee3d35a9157cd8c)
on x86_64 Linux.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9122


Andrei Alexandrescu <andrei erdani.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |andrei erdani.com
         Resolution|                            |FIXED



PDT ---
Fixed, probably with https://github.com/D-Programming-Language/phobos/pull/1312

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
May 27 2013