Skip to content
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

Add material to stdio handling #973

Closed
wants to merge 1 commit into from
Closed

Add material to stdio handling #973

wants to merge 1 commit into from

Conversation

mahkoh
Copy link
Contributor

@mahkoh mahkoh commented Mar 13, 2015

No description provided.

@mahkoh
Copy link
Contributor Author

mahkoh commented Mar 13, 2015

And here is how you would handle #899 (comment) with this design:

Since you're writing a TUI, you're interacting with fds 0 and 1 directly anyway. Therefore, at the start of your program, you set thread::set_stdout to io::Sink and thread::set_stderr to a log file.

Similarly this allows --test to properly capture not only the output of tests but also the output of threads spawned by the tests.

@l0kod
Copy link

l0kod commented Mar 13, 2015

Unfortunately, the Windows console do not make Write nor Read usable in a generic way.

cc #972

@mahkoh
Copy link
Contributor Author

mahkoh commented Mar 13, 2015

This RFC does not touch the raw versions.

@reem
Copy link

reem commented Mar 14, 2015

I might just not understand some fundamental limitation of the design space, but I'm curious why concurrent synchronization is being used (Arc and Mutex) to control a thread-local variable, which seems to only be modifiable from one thread. As a result, Rc and RefCell could be used, which would be more efficient.

@mahkoh
Copy link
Contributor Author

mahkoh commented Mar 14, 2015

@reem

I'm curious why concurrent synchronization is being used

+Unless other streams or another buffer mode has been explicitly specified via
+the thread-builder, these settings will be inherited by child-threads.

@reem
Copy link

reem commented Mar 14, 2015

Ah, I figured I had just missed something.

@aturon
Copy link
Member

aturon commented Mar 18, 2015

I think making println and panic reference a thread-local, inherited, overridable notion of stdout and stderr is a good move, for composability/capture purposes. So 👍 to the overall idea here.

One question: are the raw versions tied to the process-level handles? That is, does std give you any way to get at these underlying handles?

I'm a little unsure about the exact signatures/locations of some of the functions proposed here, but I want to think a bit more about a possible alternative for concrete comparison. I'll try to do so soon.

* `stdin` - wraps `thread::stdin`. All operations on `Stdin` directly
will acquire the lock internally. A `lock` method is provided to acquire
exclusive access to the stream for a period of time so that relocking is not
necessary.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why lock on thread local streams?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not thread local.

@mahkoh
Copy link
Contributor Author

mahkoh commented Mar 18, 2015

@aturon

One question: are the raw versions tied to the process-level handles? That is, does std give you any way to get at these underlying handles?

This RFC does not make any changes to the raw section which is marked as a sketch anyway. Raw handles will have to refer to the 0, 1, 2 fds on unix directly.

@Ericson2314
Copy link
Contributor

Is there any way to make some of this more opt-in so threads that don't do IO don't need to carry all this baggage around? All the behind the signs dynamic dispatch and thread local stuff reminds me a bit of the old green/native IO system.

I'm of the opinion that the standard streams are classic stupid arbitrary "singletons", and thus just plain bad design and holdovers from another era. The fact that we need to such things as are proposed here to fix them I take is evidence of the fact. I rather hook up panicking to the liblog infrastructure than bake this stuff into std::thread.

@aturon aturon self-assigned this Mar 19, 2015
@mahkoh
Copy link
Contributor Author

mahkoh commented Mar 21, 2015

all this baggage around?

Four pointers and a few atomic operations when you create a thread.

classic stupid arbitrary "singletons"

You're suggesting removing thread local storage and println from the language. That's an interesting thought.

@aturon
Copy link
Member

aturon commented Apr 9, 2015

RFC issue #1050

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants