Skip to content

std: Don't deadlock/panic on recursive prints #23798

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 28, 2015

Conversation

alexcrichton
Copy link
Member

Previously a panic was generated for recursive prints due to a double-borrow of
a RefCell. This was solved by the second borrow's output being directed
towards the global stdout instead of the per-thread stdout (still experimental
functionality).

After this functionality was altered, however, recursive prints still deadlocked
due to the overridden write_fmt method which locked itself first and then
wrote all the data. This was fixed by removing the override of the write_fmt
method. This means that unlocked usage of write! on a Stdout/Stderr may be
slower due to acquiring more locks, but it's easy to make more performant with a
call to .lock().

Closes #23781

@rust-highfive
Copy link
Contributor

r? @aturon

(rust_highfive has picked a reviewer for you, use r? to override)

@aturon
Copy link
Member

aturon commented Mar 27, 2015

We could eventually use a re-entrant lock, as well, but this is fine for now.

@bors: r+ 2191701

@bors
Copy link
Collaborator

bors commented Mar 28, 2015

☔ The latest upstream changes (presumably #23796) made this pull request unmergeable. Please resolve the merge conflicts.

Previously a panic was generated for recursive prints due to a double-borrow of
a `RefCell`. This was solved by the second borrow's output being directed
towards the global stdout instead of the per-thread stdout (still experimental
functionality).

After this functionality was altered, however, recursive prints still deadlocked
due to the overridden `write_fmt` method which locked itself first and then
wrote all the data. This was fixed by removing the override of the `write_fmt`
method. This means that unlocked usage of `write!` on a `Stdout`/`Stderr` may be
slower due to acquiring more locks, but it's easy to make more performant with a
call to `.lock()`.

Closes rust-lang#23781
@alexcrichton
Copy link
Member Author

@bors: r=aturon e2fd2df

@bors
Copy link
Collaborator

bors commented Mar 28, 2015

⌛ Testing commit e2fd2df with merge 9f9e251...

bors added a commit that referenced this pull request Mar 28, 2015
Previously a panic was generated for recursive prints due to a double-borrow of
a `RefCell`. This was solved by the second borrow's output being directed
towards the global stdout instead of the per-thread stdout (still experimental
functionality).

After this functionality was altered, however, recursive prints still deadlocked
due to the overridden `write_fmt` method which locked itself first and then
wrote all the data. This was fixed by removing the override of the `write_fmt`
method. This means that unlocked usage of `write!` on a `Stdout`/`Stderr` may be
slower due to acquiring more locks, but it's easy to make more performant with a
call to `.lock()`.

Closes #23781
@bors
Copy link
Collaborator

bors commented Mar 28, 2015

@bors bors merged commit e2fd2df into rust-lang:master Mar 28, 2015
@alexcrichton alexcrichton deleted the issue-23781 branch April 2, 2015 19:45
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Nested println!() statements fail
4 participants