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


--- Comment #0 from John Colvin <john.loughran.colvin gmail.com> 2012-12-07
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


--- Comment #1 from David Eagen <david eagen.com> 2013-01-03 04:44:21 PST ---
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


--- Comment #2 from David Eagen <david eagen.com> 2013-01-03 05:51:35 PST ---
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


--- Comment #3 from Martin Krejcirik <mk krej.cz> 2013-03-31 15:59:08 PDT ---
Code from comment #1 works for me in 32 bit, but I get the same error message
("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


--- Comment #4 from Zhenya Chapovsky <zheny list.ru> 2013-04-19 10:02:44 PDT ---
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


--- Comment #5 from Tavi Cacina <octavian.cacina outlook.com> 2013-04-23
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


--- Comment #6 from Martin Nowak <code dawg.eu> 2013-05-14 20:07:55 PDT ---
(In reply to comment #5)
 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


--- Comment #7 from Tavi Cacina <octavian.cacina outlook.com> 2013-05-14
23:54:37 PDT ---
(In reply to comment #6)
 
 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; } See #10017 - Can not assign to a Variant another Variant holding a bigger 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



--- Comment #8 from David Eagen <david eagen.com> 2013-05-27 18:10:07 PDT ---
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


--- Comment #9 from Andrei Alexandrescu <andrei erdani.com> 2013-05-27 19:30:03
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