From d68e4da928a11416058a5ce706d943ccd2319a48 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Tue, 2 Sep 2014 15:03:43 -0400 Subject: [PATCH 1/6] #6989 - attempt 1 on Tid.toString() --- std/concurrency.d | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/std/concurrency.d b/std/concurrency.d index 1c2859d806d..fab53b193f2 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -69,6 +69,7 @@ private import std.algorithm; import std.datetime; import std.exception; + import std.format; import std.range; import std.string; import std.traits; @@ -321,6 +322,27 @@ private: MessageBox mbox; + +public: + + /// Generate a convenient string for identifying this Tid. + public string toString() { + // HELPME: This should be changed to not allocate. I'm not versed on + // avoiding the GC. + if (mbox.receiveThread) { + auto writer = appender!string(); + formattedWrite(writer, "Tid(0x%x)", mbox.receiveThread.toHash()); + return writer.data; + } else { + return "Tid(NOT STARTED)"; + } + } + + /// Get the Thread that is receiving messages for this Tid + Thread receiveThread() { + return mbox.receiveThread; + } + } @@ -484,6 +506,7 @@ private Tid _spawn(F, T...)( bool linked, F fn, T args ) { mbox = spawnTid.mbox; owner = ownerTid; + mbox.receiveThread = Thread.getThis; fn( args ); } @@ -1447,6 +1470,14 @@ private size_t m_localMsgs; size_t m_maxMsgs; bool m_closed; + + public: + /// Reference to the thread receiving messages from this MessageBox. + /// Note that this is invalid until spawn() or spawnLinked() is + /// called. + Thread receiveThread; + + } From dc863b31be67564977c1248bd07f4bfdb798767a Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Wed, 3 Sep 2014 19:21:34 -0400 Subject: [PATCH 2/6] code formatting, use sink --- std/concurrency.d | 28 ++++++++++++---------------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/std/concurrency.d b/std/concurrency.d index fab53b193f2..f00a463833c 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -326,21 +326,17 @@ private: public: /// Generate a convenient string for identifying this Tid. - public string toString() { - // HELPME: This should be changed to not allocate. I'm not versed on - // avoiding the GC. - if (mbox.receiveThread) { - auto writer = appender!string(); - formattedWrite(writer, "Tid(0x%x)", mbox.receiveThread.toHash()); - return writer.data; - } else { - return "Tid(NOT STARTED)"; - } + void toString(scope void delegate(const(char)[]) sink) + { + if (mbox.receiveThread) + formattedWrite(sink, "Tid(0x%x)", mbox.receiveThread.toHash()); + else + sink.put("Tid(NOT STARTED)"); } /// Get the Thread that is receiving messages for this Tid Thread receiveThread() { - return mbox.receiveThread; + return mbox.receiveThread; } } @@ -506,7 +502,7 @@ private Tid _spawn(F, T...)( bool linked, F fn, T args ) { mbox = spawnTid.mbox; owner = ownerTid; - mbox.receiveThread = Thread.getThis; + mbox.receiveThread = Thread.getThis; fn( args ); } @@ -1472,11 +1468,11 @@ private bool m_closed; public: - /// Reference to the thread receiving messages from this MessageBox. - /// Note that this is invalid until spawn() or spawnLinked() is - /// called. - Thread receiveThread; + /// Reference to the thread receiving messages from this MessageBox. + /// Note that this is invalid until spawn() or spawnLinked() is + /// called. + Thread receiveThread; } From a6f503e9c18fa57ad920be077c2fe5a2d27337d8 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Sat, 11 Oct 2014 13:23:34 -0400 Subject: [PATCH 3/6] update docs, style, use thread:id scheme --- std/concurrency.d | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/std/concurrency.d b/std/concurrency.d index f00a463833c..d0739f36edd 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -325,17 +325,37 @@ private: public: - /// Generate a convenient string for identifying this Tid. + /** + * Generate a convenient string for identifying this Tid. This is only + * useful to see if Tid's that are currently executing are the same or + * different, e.g. for logging and debugging. It is potentially possible + * that a Tid executed in the future will have the same toString() output + * as another Tid that has already terminated. + * + * Note that Tid's will eventually be capable of running on Fibers, and + * perhaps processes or other things. This string scheme will change + * accordingly. + */ void toString(scope void delegate(const(char)[]) sink) { if (mbox.receiveThread) - formattedWrite(sink, "Tid(0x%x)", mbox.receiveThread.toHash()); + formattedWrite(sink, "Tid(thread:0x%x)", mbox.receiveThread.toHash()); else - sink.put("Tid(NOT STARTED)"); + sink.put("Tid(new)"); } - /// Get the Thread that is receiving messages for this Tid - Thread receiveThread() { + /** + * Get the Thread that is receiving messages for this Tid. + * + * Note that Tid's will eventually be capable of running on Fibers, and + * perhaps processes or other things. This Thread reference will be null + * for those cases. + * + * Returns: + * Thread running this Tid, or null if this Tid has not been spawned. + */ + Thread receiveThread() + { return mbox.receiveThread; } @@ -1467,8 +1487,6 @@ private size_t m_maxMsgs; bool m_closed; - public: - /// Reference to the thread receiving messages from this MessageBox. /// Note that this is invalid until spawn() or spawnLinked() is /// called. From 482608c7c1342049db547c5178dbb8c6d6fbd175 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Thu, 30 Oct 2014 18:13:37 -0400 Subject: [PATCH 4/6] use MessageBox hash, remove running thread --- std/concurrency.d | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) diff --git a/std/concurrency.d b/std/concurrency.d index d0739f36edd..fc98d7ec998 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -331,32 +331,10 @@ public: * different, e.g. for logging and debugging. It is potentially possible * that a Tid executed in the future will have the same toString() output * as another Tid that has already terminated. - * - * Note that Tid's will eventually be capable of running on Fibers, and - * perhaps processes or other things. This string scheme will change - * accordingly. */ void toString(scope void delegate(const(char)[]) sink) { - if (mbox.receiveThread) - formattedWrite(sink, "Tid(thread:0x%x)", mbox.receiveThread.toHash()); - else - sink.put("Tid(new)"); - } - - /** - * Get the Thread that is receiving messages for this Tid. - * - * Note that Tid's will eventually be capable of running on Fibers, and - * perhaps processes or other things. This Thread reference will be null - * for those cases. - * - * Returns: - * Thread running this Tid, or null if this Tid has not been spawned. - */ - Thread receiveThread() - { - return mbox.receiveThread; + formattedWrite(sink, "Tid(%x)", mbox.toHash()); } } @@ -522,7 +500,6 @@ private Tid _spawn(F, T...)( bool linked, F fn, T args ) { mbox = spawnTid.mbox; owner = ownerTid; - mbox.receiveThread = Thread.getThis; fn( args ); } @@ -1487,11 +1464,6 @@ private size_t m_maxMsgs; bool m_closed; - /// Reference to the thread receiving messages from this MessageBox. - /// Note that this is invalid until spawn() or spawnLinked() is - /// called. - Thread receiveThread; - } From bf51ee87f1a35691d713248c782cca8601ea3ad0 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Tue, 4 Nov 2014 08:17:17 -0500 Subject: [PATCH 5/6] use mbox address --- std/concurrency.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/concurrency.d b/std/concurrency.d index fc98d7ec998..4f14f3ef5b1 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -334,7 +334,7 @@ public: */ void toString(scope void delegate(const(char)[]) sink) { - formattedWrite(sink, "Tid(%x)", mbox.toHash()); + formattedWrite(sink, "Tid(%x)", &mbox); } } From b0edb88696622c6c981c0d3657a42f4e0ff5cc01 Mon Sep 17 00:00:00 2001 From: Kevin Lamonte Date: Tue, 4 Nov 2014 18:01:38 -0500 Subject: [PATCH 6/6] moved import --- std/concurrency.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/concurrency.d b/std/concurrency.d index 4f14f3ef5b1..b7e371fb5fd 100644 --- a/std/concurrency.d +++ b/std/concurrency.d @@ -69,7 +69,6 @@ private import std.algorithm; import std.datetime; import std.exception; - import std.format; import std.range; import std.string; import std.traits; @@ -334,6 +333,7 @@ public: */ void toString(scope void delegate(const(char)[]) sink) { + import std.format; formattedWrite(sink, "Tid(%x)", &mbox); }