On Jul 8, 2013, at 8:08 AM, Adam D. Ruppe <[email protected]> wrote:
> On Monday, 8 July 2013 at 14:53:25 UTC, John Colvin wrote: >> I wonder if one could somehow register a pre-existing thread with >> std.concurrency, being careful not to introduce any reference that lets in >> the garbage collector. > > There is a thread_attachThis() in core.thread that "Registers the calling > thread for use with the D Runtime. " and returns a Thread object. > > However, I think that registers it with the GC too so it defeats the purpose > of skipping Thread in the first place. Right. The point of that routine is to make it so an external thread can safely reference garbage collected memory. > Looking at the source of std.concurrency, it looks like it just has a thread > local mailbox for each one, that is created when you call thisTid() the first > time. > > idk if that's actually all that is done, or if TLS needs any special work > (I've never actually used pthreads directly), but maybe you could try calling > that thisTid() function in the thread you make yourself and then send it a > message and see what happens. You'd really need to call thread_attachThis() first, since std.concurrency uses garbage collected memory for message passing.
