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

[WIP/RFC] Add some more IO locks to printing #32159

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

iamed2
Copy link
Contributor

@iamed2 iamed2 commented May 27, 2019

Right now you can get mixed output with async code:

function foo(n)
    @sync begin
        @async (sleep(0.05); printstyled(stdout, ntuple(_ -> "foo", n)...; color=:blue))
        @async print(stdout, ntuple(_ -> "bar", n)...)
    end
end
julia> foo(30)
barfoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoofoobarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarbarTask (done) @0x0000000117d2d690

In this case printstyled is actually doing a single print under the hood, after writing the string to a buffer. While there is a lock in vararg print, there was no lock in single-string print. This means that the foo string could be shoved right in the middle of the bars as it was ignoring the lock that vararg print had.

AFAICT this just means we need more locks. I have added some locks. If people agree, I will add all the locks.

I also think that lock(f, x::AbstrackLock) should probably be expanded to lock(f, x::Any).

@JeffBezanson JeffBezanson added the I/O Involving the I/O subsystem: libuv, read, write, etc. label May 28, 2019
@omus
Copy link
Member

omus commented Feb 14, 2020

I'm in favour of this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I/O Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants