www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 4957] New: std.concurrency does not allow to pass Tid in struct fields

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

           Summary: std.concurrency does not allow to pass Tid in struct
                    fields
           Product: D
           Version: D2
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: osa8aso gmail.com


--- Comment #0 from osa8aso gmail.com 2010-09-29 12:14:23 PDT ---
send() allows to Tid only as a top-level parameter. Using Tid in a struct does
not work. This compiles:
----
import std.concurrency;
void main() {
    send( thisTid, thisTid );
    receive( Tid );
}
----

This fails to compile:
----
import std.concurrency;
struct Message { Tid tid; }
void main() {
    send( thisTid, Message( thisTid ) );
    receive( ( Message ) {} );
}
---
std/concurrency.d(363): Error: static assert  "Aliases to mutable thread-local
data not allowed."
c.d(4):        instantiated from here: send!(Message)

So Tid is not mutable when passed to send() directly, but as a part of struct
Message, it suddenly becomes mutable?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Sep 29 2010
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=4957


ratchet freak <ratchet.freak gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ratchet.freak gmail.com


--- Comment #1 from ratchet freak <ratchet.freak gmail.com> 2011-05-12 15:28:20
PDT ---
I've found how it comes:

std.concurrency defines the following testing template for sending parameters
along

//line 49
template hasLocalAliasing(T...)
    {
        static if( !T.length )
            enum hasLocalAliasing = false;
        else
            enum hasLocalAliasing = (std.traits.hasLocalAliasing!(T[0]) &&
!is(T[0] == Tid)) ||
                                    std.concurrency.hasLocalAliasing!(T[1 ..
$]);
    }

which handles Tid as a special case which doesn't happen when it's not
top-level

Tid itself is of the form:

//lines 272
struct Tid
{
    void send(T...)( T vals )
    {
        static assert( !hasLocalAliasing!(T),
                       "Aliases to mutable thread-local data not allowed." );
        _send( this, vals );
    }


private:
    this( MessageBox m )
    {
        mbox = m;
    }


    MessageBox  mbox;
}

MessageBox here does not pass the test of !std.traits.hasLocalAliasing (it's a
class object)

quick fix: make mbox in Tid shared and cast accesses to it to thread local this
allows Tid to pass the !std.traits.hasLocalAliasing test *as one would expect
from it*

struct Tid
{
    void send(T...)( T vals )
    {
        static assert( !hasLocalAliasing!(T),
                       "Aliases to mutable thread-local data not allowed." );
        _send( this, vals );
    }


private:
    this( MessageBox m )
    {
        mbox = cast(shared)m;
    }


    shared MessageBox  mbox;
}

//lines 419
private void _send(T...)( MsgType type, Tid tid, T vals )
{
    (cast(MessageBox)tid.mbox).put( Message( type, vals ) );
}

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


Sean Kelly <sean invisibleduck.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
                 CC|                            |sean invisibleduck.org


--- Comment #2 from Sean Kelly <sean invisibleduck.org> 2011-05-16 11:23:18 PDT
---
Curses!  Seems I'll have to apply 'shared' to private members of Tid.

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


Johan Hernandez <thepumpkin1979 gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |thepumpkin1979 gmail.com


--- Comment #3 from Johan Hernandez <thepumpkin1979 gmail.com> 2012-07-14
03:06:04 PDT ---
I ran into this issue too. We need a fix :(

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jul 14 2012