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

Writing to IOBuffer from @async/@sync #27266

Closed
rofinn opened this issue May 25, 2018 · 2 comments
Closed

Writing to IOBuffer from @async/@sync #27266

rofinn opened this issue May 25, 2018 · 2 comments
Labels
io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@rofinn
Copy link
Contributor

rofinn commented May 25, 2018

Disclaimer: I'm not positive if this is an issue or just a behaviour change, but I didn't find an existing issue/topic on github or discourse.

Issue

Specifically, the following sample code seems to run fine on 0.6, but fails on a recent nightly.

using Base.Test, Compat

struct Logger
    parent::Union{Logger, Compat.Nothing}
    handle::Union{IO, Compat.Nothing}
end

io = IOBuffer()

root = Logger(nothing, io)
a = Logger(root, nothing)
b = Logger(a, nothing)

function log(logger::Logger, str)
    @async begin
        if logger.handle !== nothing
            println(logger.handle, str)
        end
    end
    if logger.parent !== nothing
        log(logger.parent, str)
    end
end

function test()
    @sync log(b, "Foo")
    @test !isempty(String(take!(io)))
end

test()

If I remove the @async on nightly then it works again.

versioninfo:

julia> versioninfo()
Julia Version 0.7.0-DEV.5214
Commit 14dbdf509a* (2018-05-24 11:25 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin17.5.0)
  CPU: Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, broadwell)
Environment:
  JULIA_EDITOR = /usr/local/bin/atom -n
  JULIA_HISTORY = /Users/rory/.playground/share/memento/.julia_history
  JULIA_PKGDIR = /Users/rory/.playground/share/memento/packages

The above code was using Compat 0.65.0

@ararslan ararslan added the io Involving the I/O subsystem: libuv, read, write, etc. label May 26, 2018
@JeffBezanson
Copy link
Member

This is a behavior change, from #27164. @sync now only waits for @asyncs that are lexically inside its argument expression. This is intended to make it easier to reason about what things it will wait for, and closer to the semantics of e.g. Cilk.

@rofinn
Copy link
Contributor Author

rofinn commented May 26, 2018

Yep, moving the @sync into the same function solved my issue. Thanks.

@rofinn rofinn closed this as completed May 26, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

No branches or pull requests

3 participants