Thread overview | |||||||||
---|---|---|---|---|---|---|---|---|---|
|
February 09, 2016 std.concurrency: ownerTid vs thisTid | ||||
---|---|---|---|---|
| ||||
Hi, The following simple program: import std.stdio, std.concurrency; void f1() { writeln("owner: ", ownerTid); writeln("worker: ", thisTid); } void main() { writeln("owner: ", thisTid); writeln("worker: ", spawn(&f1)); } Gives me the following result: owner: Tid(18fd58) worker: Tid(18fd58) owner: Tid(24afe38) worker: Tid(24afe38) Is it correct? My expectation was that: - thisTid called from main will be the same as ownerTid called from f1 - thisTid called from f1 will be the same as value returned by spawn() Thank you for your help. |
February 09, 2016 Re: std.concurrency: ownerTid vs thisTid | ||||
---|---|---|---|---|
| ||||
Posted in reply to miazo Attachments:
| It is OK, I guess the output is just mixed On Tue, Feb 9, 2016 at 4:35 PM, miazo via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote: > Hi, > > The following simple program: > > import std.stdio, std.concurrency; > > void f1() { > writeln("owner: ", ownerTid); > writeln("worker: ", thisTid); > } > > void main() { > writeln("owner: ", thisTid); > writeln("worker: ", spawn(&f1)); > } > > Gives me the following result: > > owner: Tid(18fd58) > worker: Tid(18fd58) > owner: Tid(24afe38) > worker: Tid(24afe38) > > Is it correct? My expectation was that: > - thisTid called from main will be the same as ownerTid called from f1 > - thisTid called from f1 will be the same as value returned by spawn() > > Thank you for your help. > > |
February 09, 2016 Re: std.concurrency: ownerTid vs thisTid | ||||
---|---|---|---|---|
| ||||
Posted in reply to Daniel Kozak | On 02/09/2016 07:52 AM, Daniel Kozak via Digitalmars-d-learn wrote:
> It is OK, I guess the output is just mixed
Yes, that's an important point but it is not the reason. (Just tested.)
I think this is just an issue with how Tid objects are printed. Otherwise, everything works as expected and although they print the same value, "worker1 != worker2" is true as well.
Ali
|
February 09, 2016 Re: std.concurrency: ownerTid vs thisTid | ||||
---|---|---|---|---|
| ||||
Attachments:
| OK it seems wierd
On Tue, Feb 9, 2016 at 4:52 PM, Daniel Kozak <kozzi11@gmail.com> wrote:
> It is OK, I guess the output is just mixed
>
> On Tue, Feb 9, 2016 at 4:35 PM, miazo via Digitalmars-d-learn < digitalmars-d-learn@puremagic.com> wrote:
>
>> Hi,
>>
>> The following simple program:
>>
>> import std.stdio, std.concurrency;
>>
>> void f1() {
>> writeln("owner: ", ownerTid);
>> writeln("worker: ", thisTid);
>> }
>>
>> void main() {
>> writeln("owner: ", thisTid);
>> writeln("worker: ", spawn(&f1));
>> }
>>
>> Gives me the following result:
>>
>> owner: Tid(18fd58)
>> worker: Tid(18fd58)
>> owner: Tid(24afe38)
>> worker: Tid(24afe38)
>>
>> Is it correct? My expectation was that:
>> - thisTid called from main will be the same as ownerTid called from f1
>> - thisTid called from f1 will be the same as value returned by spawn()
>>
>> Thank you for your help.
>>
>>
>
|
February 09, 2016 Re: std.concurrency: ownerTid vs thisTid | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Tuesday, 9 February 2016 at 15:55:34 UTC, Ali Çehreli wrote:
> On 02/09/2016 07:52 AM, Daniel Kozak via Digitalmars-d-learn wrote:
>> It is OK, I guess the output is just mixed
>
> Yes, that's an important point but it is not the reason. (Just tested.)
>
> I think this is just an issue with how Tid objects are printed. Otherwise, everything works as expected and although they print the same value, "worker1 != worker2" is true as well.
>
> Ali
Well, I'm not concerned about the order of the output but the actual values of these ids. Shouldn't it be rather:
owner: Tid(18fd58)
worker: Tid(24afe38)
owner: Tid(18fd58)
worker: Tid(24afe38)
or
owner: Tid(24afe38)
worker: Tid(18fd58)
owner: Tid(24afe38)
worker: Tid(18fd58)
?
|
February 09, 2016 Re: std.concurrency: ownerTid vs thisTid | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli Attachments:
| You are right: import std.stdio, std.concurrency; import std.concurrency : MessageBox; struct MyTid { MessageBox mbox; } static void f1() { auto tT = cast(MyTid)thisTid; auto oT = cast(MyTid)ownerTid; writeln("F1:worker: ", cast(void*)tT.mbox); writeln("F1:owner: ", cast(void*)oT.mbox); } void main() { auto tT = cast(MyTid)thisTid(); auto sT = cast(MyTid)spawn(&f1); writeln("Main:worker: ", cast(void *)sT.mbox); writeln("Main:owner: ", cast(void *)tT.mbox); } On Tue, Feb 9, 2016 at 4:55 PM, Ali Çehreli < digitalmars-d-learn@puremagic.com> wrote: > On 02/09/2016 07:52 AM, Daniel Kozak via Digitalmars-d-learn wrote: > >> It is OK, I guess the output is just mixed >> > > Yes, that's an important point but it is not the reason. (Just tested.) > > I think this is just an issue with how Tid objects are printed. Otherwise, everything works as expected and although they print the same value, "worker1 != worker2" is true as well. > > Ali > > |
February 09, 2016 Re: std.concurrency: ownerTid vs thisTid | ||||
---|---|---|---|---|
| ||||
https://github.com/D-Programming-Language/phobos/blob/v2.070.0/std/concurrency.d#L340 formattedWrite(sink, "Tid(%x)", &mbox); should be: formattedWrite(sink, "Tid(%x)", cast(void *)mbox); On Tue, Feb 9, 2016 at 5:25 PM, Daniel Kozak <kozzi11@gmail.com> wrote: > You are right: > import std.stdio, std.concurrency; > import std.concurrency : MessageBox; > > struct MyTid > { > MessageBox mbox; > } > > static void f1() { > auto tT = cast(MyTid)thisTid; > auto oT = cast(MyTid)ownerTid; > writeln("F1:worker: ", cast(void*)tT.mbox); > writeln("F1:owner: ", cast(void*)oT.mbox); > } > > void main() { > auto tT = cast(MyTid)thisTid(); > auto sT = cast(MyTid)spawn(&f1); > writeln("Main:worker: ", cast(void *)sT.mbox); > writeln("Main:owner: ", cast(void *)tT.mbox); > } > > > On Tue, Feb 9, 2016 at 4:55 PM, Ali Çehreli <digitalmars-d-learn@puremagic.com> wrote: >> >> On 02/09/2016 07:52 AM, Daniel Kozak via Digitalmars-d-learn wrote: >>> >>> It is OK, I guess the output is just mixed >> >> >> Yes, that's an important point but it is not the reason. (Just tested.) >> >> I think this is just an issue with how Tid objects are printed. Otherwise, everything works as expected and although they print the same value, "worker1 != worker2" is true as well. >> >> Ali >> > |
Copyright © 1999-2021 by the D Language Foundation