digitalmars.D.learn - std.concurrency: ownerTid vs thisTid
- miazo (22/22) Feb 09 2016 Hi,
- Daniel Kozak via Digitalmars-d-learn (3/23) Feb 09 2016 It is OK, I guess the output is just mixed
- =?UTF-8?Q?Ali_=c3=87ehreli?= (6/7) Feb 09 2016 Yes, that's an important point but it is not the reason. (Just tested.)
- miazo (13/22) Feb 09 2016 Well, I'm not concerned about the order of the output but the
- Daniel Kozak via Digitalmars-d-learn (22/30) Feb 09 2016 You are right:
- Daniel Kozak via Digitalmars-d-learn (5/40) Feb 09 2016 https://github.com/D-Programming-Language/phobos/blob/v2.070.0/std/concu...
- Daniel Kozak via Digitalmars-d-learn (2/35) Feb 09 2016
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.
Feb 09 2016
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.
Feb 09 2016
On 02/09/2016 07:52 AM, Daniel Kozak via Digitalmars-d-learn wrote:It is OK, I guess the output is just mixedYes, 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
Feb 09 2016
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: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) ?It is OK, I guess the output is just mixedYes, 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
Feb 09 2016
You are right: import std.stdio, std.concurrency; import std.concurrency : MessageBox; struct MyTid { MessageBox mbox; } static void f1() { auto tT =3D cast(MyTid)thisTid; auto oT =3D cast(MyTid)ownerTid; writeln("F1:worker: ", cast(void*)tT.mbox); writeln("F1:owner: ", cast(void*)oT.mbox); } void main() { auto tT =3D cast(MyTid)thisTid(); auto sT =3D 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 =C3=87ehreli < 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 mixedYes, 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 !=3D worker2" is true as well. Ali
Feb 09 2016
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 mixedYes, 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
Feb 09 2016
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.
Feb 09 2016