-
-
Notifications
You must be signed in to change notification settings - Fork 746
Issue 6989 - create a better string representation of Tid #2482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
std/concurrency.d
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't use this overload if you want to avoid the GC; use this instead:
void toString(scope void delegate(const(char)[]) sink)
Instead of constructing a string, use sink.put(...)
to append data to the output. If you're using formattedWrite
, you can pass sink
in place of the writer.
Also, please follow the Phobos coding style guide for all code submissions: http://dlang.org/dstyle.html Specifically, don't use "Egyptian braces"; instead, put the opening |
std/concurrency.d
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use 4 spaces instead of tabs. (Same elsewhere.)
As far as a unittest is concerned, you can probably just compare the result of
Note that unittests have access to private members within the module, so you don't have to worry about adding accessors to obtain the information you need to generate the expected formatting of |
Oh, and the unittest should probably also test for the |
There is one major issue with the concept of this PR : |
A trivial way out of this problem is to print TId with some sort of schema a-la URIs.
These could be followed by @complexmath What do you think? |
std/concurrency.d
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't importing std.format implicitly pull in the better part of Phobos? Can we not do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, please move the import to function body
The big question for me is whether we want to try and have this identifier remain unique for the entire length of the program, or if we can accept them only being unique for as long as a thread is alive. Like it would be easy enough to use the address of the MessageBox plus some adornment in the latter case. The other question I have is whether this is just for logging or if we want these to actually be passed around and used as a means to send a message to a thread. Erlang works this way, for example, but I think it tends to be problematic, particularly for long-running programs. Ultimately, what I'd like is for threads that are intended to be referenced by name to be done via a registry. Then what we're really doing is referencing a thread that we know will handle some specific request and we don't actually care if it's the same thread we talked to last time or if it's a different one. I created register() for this purpose, and when std.concurrency supports IPC there will be a registry host process to serve the same function. What such a registry would return is more a bunch of info for how to contact a thread rather than a pretty identifier, as the needed info might include an IP address, port, protocol, registered thread name, etc. So... for plain old in-process thread identifiers, I think we need to establish just what the use case is. I'd prefer to go the easy route and use something like the MessageBox address, but could probably be convinced to create an atomic integer so every spawned thread gets its own "unique" id, though efficiently dealing will rollover in this case is tricky. |
A registry is the way to go for named tasks, I agree. There is already |
std/concurrency.d
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK hash of a pointer is not unique nor meaningful.
I think non-unique thread/fiber ID is good enough initially. Right now it is most useful for debugging purposes and introduction of cross-process messages is likely to warrant more complicated naming scheme anyway. Let's do KISS for now. |
How about document that the exact contents of the string may change and it is only for debugging purposes? |
@yebblies: Yep, we definitely need something along the lines of that anyway. |
Absolutely. It still needs to be practically useful though :) |
This has popped up recently again in context of logging. |
@klamonte do you have time to move forward with this? |
@klamonte please avoid merge commits - 55 changed files is certainly misrepresentation of this pull's changes. And a hint - github doesn't notify contributors of any changes to commits of a pull, only comments. |
@DmitryOlshansky Sorry about that, thanks for the tips! Is there anything I can do at this stage to reduce the clutter from the upstream merge? @Dicebot How does this look? (Sorry about the clutter from the upstream merge.) |
@klamonte please do this to get rid of merge commit:
Also I recommend to create dedicated branches for pull requests if you ever will want to create another one ;) |
@DmitryOlshansky @Dicebot How does this look? |
Thanks, commit history is much better. On actual changes - right now I am convinced that tracking actual thread is impractical and some sort of message box pointer representation is good enough. Ideally this needs @complexmath judgement call but he seems a bit busy lately. |
Good idea. @klamonte - one way to make sure history is clutter free is to always use: pull --rebase upstream master before pushing new changes. That would however require forced push ( |
I'm in favor of using the MessageBox pointer. It's already there and is guaranteed to be unique for the lifetime of a thread. Just format it in a way that makes sense, say a hex number without the leading "0X". Also, do we need a toString call? It would be nice if we could simply return the id as a size_t or something and let the caller format it. |
@complexmath Doh, I used its hash rather than address, but is this closer to what you have in mind? I'd be fine with letting the caller have an id in lieu of a string, but would also like formattedWrite(writer, "%s", someTid) to emit that id. Can that be done with just a change in std.concurrency? |
@klamonte Hash is NOT unique. Just use the pointer. Also |
I was thinking about possibility of using some simple perfect hashing for a pointer to ensure that no one will be tempted to do |
The hash of a pointer is probably just the pointer itself anyway. Either way, there's no point in the extra computation. @Dicebot I don't think so. The id we return is just an identifier. If someone exploits knowledge of where this identifier comes from it's their problem if their code breaks or behaves erratically, say if we change how the id is computed. |
Well XOR-masking a pointer or subtracting some big value is a 1:1 mapping that's cheap and would undermine blind use of casts. |
Unrelated tester failure? |
Seems to fell out of sight. Just rebase and let's pull it? |
I agree, let's pull this. |
Superseded by: #2772 |
Original discussion here: #1582
The basic premise is that we will let Tid's expose the Thread that is receiving messages, without actually exposing the MessageBox itself. There exists a short window after spawn()/spawnLinked() where Tid.receiveThread is null (the thread hasn't yet set it in _spawn()).
I am very new to the Phobos codebase, my apologies if I am grossly breaking the process. Two areas I know this change is weak and needs help: