Re: Sending an immutable object to a thread

2015-07-24 Thread anonymous via Digitalmars-d-learn
On Friday, 24 July 2015 at 21:51:44 UTC, Frank Pagliughi wrote: So then: is there a pointer notation to which you can cast the "B" reference, which thus points to the heap, but retains type identity of the heap object? There's no straight forward way to do that. D has no types for the actual

Re: Sending an immutable object to a thread

2015-07-24 Thread Frank Pagliughi via Digitalmars-d-learn
On Friday, 24 July 2015 at 19:28:35 UTC, anonymous wrote: I haven't followed the discussion, so I may be missing the point here. I started by asking how to send a reference to an immutable class object from one thread to another if the reference is one of several parameters being sent. The co

Re: Sending an immutable object to a thread

2015-07-24 Thread anonymous via Digitalmars-d-learn
On Friday, 24 July 2015 at 18:55:26 UTC, Frank Pagliughi wrote: So then, of course, I hope/wonder/assume that the pointer to the heap is sufficient to keep the heap memory alive, and that this would be OK from the GC perspective to do something like this: B* make_b_thing(int i) { cast(B*) n

Re: Sending an immutable object to a thread

2015-07-24 Thread Frank Pagliughi via Digitalmars-d-learn
On Friday, 24 July 2015 at 18:02:58 UTC, Ali Çehreli wrote: Although the example casts to void*, ubyte* and others are possible as well, and casting back to the correct class type seems to work: Thanks, Ali. I just tried a few things, and apparently, you don't need to go to a different type

Re: Sending an immutable object to a thread

2015-07-24 Thread Ali Çehreli via Digitalmars-d-learn
On 07/23/2015 06:48 AM, Frank Pagliughi wrote: > So, passing a pointer to a stack-based reference from one thread is > another is not necessarily a good thing to do, as the original reference > might disappear while the thread is using it. Right. > Is there a way to get the address of the actua

Re: Sending an immutable object to a thread

2015-07-23 Thread Frank Pagliughi via Digitalmars-d-learn
On Thursday, 23 July 2015 at 09:05:12 UTC, Marc Schütz wrote: It is not safe, but for a different reason: `mt` is already a _reference_ to the actual object (that's how classes behave in D). This reference is located in a register or on the stack, and `&mt` is therefore a pointer into the sta

Re: Sending an immutable object to a thread

2015-07-23 Thread via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 17:17:17 UTC, Frank Pagliughi wrote: Or, to put it another way, getting threads out of the equation, is this safe? class MyThing { ... } MyThing* create_a_thing() { MyThing mt = new MyThing(); do_something_with(mt); return &mt; } void main() {

Re: Sending an immutable object to a thread

2015-07-22 Thread rsw0x via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 17:17:17 UTC, Frank Pagliughi wrote: On Wednesday, 22 July 2015 at 09:04:49 UTC, Marc Schütz wrote: But as long as the original pointer is still on the stack, that one _will_ keep the object alive. It is only a problem if all pointers to a GC managed object are s

Re: Sending an immutable object to a thread

2015-07-22 Thread Frank Pagliughi via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 09:04:49 UTC, Marc Schütz wrote: But as long as the original pointer is still on the stack, that one _will_ keep the object alive. It is only a problem if all pointers to a GC managed object are stored in places the GC isn't informed about. Sorry, I have gotten

Re: Sending an immutable object to a thread

2015-07-22 Thread rsw0x via Digitalmars-d-learn
On Wednesday, 22 July 2015 at 09:04:49 UTC, Marc Schütz wrote: On Tuesday, 21 July 2015 at 21:50:35 UTC, rsw0x wrote: On Tuesday, 21 July 2015 at 21:44:07 UTC, rsw0x wrote: [...] addendum: http://dlang.org/garbage.html [...] [...] I believe this implies that it would *not* keep the obj

Re: Sending an immutable object to a thread

2015-07-22 Thread via Digitalmars-d-learn
On Tuesday, 21 July 2015 at 21:50:35 UTC, rsw0x wrote: On Tuesday, 21 July 2015 at 21:44:07 UTC, rsw0x wrote: On Sunday, 19 July 2015 at 17:12:07 UTC, rsw0x wrote: [...] wow, I don't even remember posting this. This is (mostly) wrong, but I'm unsure if a pointer to another pointer on the st

Re: Sending an immutable object to a thread

2015-07-21 Thread rsw0x via Digitalmars-d-learn
On Tuesday, 21 July 2015 at 21:44:07 UTC, rsw0x wrote: On Sunday, 19 July 2015 at 17:12:07 UTC, rsw0x wrote: [...] wow, I don't even remember posting this. This is (mostly) wrong, but I'm unsure if a pointer to another pointer on the stack would correctly keep its object alive(but, I believ

Re: Sending an immutable object to a thread

2015-07-21 Thread rsw0x via Digitalmars-d-learn
On Sunday, 19 July 2015 at 17:12:07 UTC, rsw0x wrote: On Sunday, 19 July 2015 at 17:04:07 UTC, Frank Pagliughi wrote: [...] Oh, yes, pointer. Ha! I didn't even think of that. Thanks. I'm not familiar with how garbage collection works in D. If the initial reference goes out of scope, and you

Re: Sending an immutable object to a thread

2015-07-21 Thread Frank Pagliughi via Digitalmars-d-learn
On Sunday, 19 July 2015 at 17:12:07 UTC, rsw0x wrote: a pointer to a pointer(or in this case, a reference) does not keep it alive. Interesting. If you de-reference the pointer and assign it back, do you get back the keep-alive? Like, in the receiving thread: void threadFunc() { receive

Re: Sending an immutable object to a thread

2015-07-19 Thread rsw0x via Digitalmars-d-learn
On Sunday, 19 July 2015 at 17:04:07 UTC, Frank Pagliughi wrote: [...] Oh, yes, pointer. Ha! I didn't even think of that. Thanks. I'm not familiar with how garbage collection works in D. If the initial reference goes out of scope, and you just have a pointer - in another thread, no less - the

Re: Sending an immutable object to a thread

2015-07-19 Thread Frank Pagliughi via Digitalmars-d-learn
It looks like passing a pointer to an immutable(Message) works as well: Oh, yes, pointer. Ha! I didn't even think of that. Thanks. I'm not familiar with how garbage collection works in D. If the initial reference goes out of scope, and you just have a pointer - in another thread, no less - th

Re: Sending an immutable object to a thread

2015-07-19 Thread Ali Çehreli via Digitalmars-d-learn
It is a pitty that although Variant is the default message type in concurrency, it still has issues: https://issues.dlang.org/buglist.cgi?quicksearch=variant%20concurrency&list_id=202195 It looks like passing a pointer to an immutable(Message) works as well: import std.stdio; import std.concu

Re: Sending an immutable object to a thread

2015-07-18 Thread Frank Pagliughi via Digitalmars-d-learn
OK, I found a couple of solutions, though if anyone can tell me something better, I would love to hear it. By making an alias to a rebindable reference, the receive() was able to create the tuple. So I renamed the class "MessageType": class MessageType { ... }; and then made a "Message"

Sending an immutable object to a thread

2015-07-18 Thread Frank Pagliughi via Digitalmars-d-learn
Hey All, I'm trying to send immutable class objects to a thread, and am having trouble if the object is one of several variables sent to the thread. For example, I have a "Message" class: class Message { ... } and I create an immutable object from it, and send it to another thread: