[Issue 4957] std.concurrency does not allow to pass Tid in struct fields

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu May 12 15:32:24 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=4957


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

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


--- Comment #1 from ratchet freak <ratchet.freak at 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: -------


More information about the Digitalmars-d-bugs mailing list