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

segfault when printing to screen from within multithreaded loop #17388

Closed
samuelpowell opened this issue Jul 12, 2016 · 5 comments
Closed

segfault when printing to screen from within multithreaded loop #17388

samuelpowell opened this issue Jul 12, 2016 · 5 comments
Labels
domain:docs This change adds or pertains to documentation domain:multithreading Base.Threads and related functionality

Comments

@samuelpowell
Copy link
Member

Nightly binary on OS X 10.11.5

  _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "?help" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.5.0-dev+5275 (2016-07-11 13:22 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit 590b4be (0 days old master)
|__/                   |  x86_64-apple-darwin13.4.0

julia> Base.Threads.nthreads()
4

julia> Base.Threads.@threads for n = 1:4
           println()
       end






signal (11): Segmentation fault: 11
while loading no file, in expression starting on line 0
uv__write at /Users/osx/buildbot/slave/package_osx10_9-x64/build/deps/srccache/libuv-ecbd6eddfac4940ab8db57c73166a7378563ebd3/src/unix/stream.c:890
uv_write2 at /Users/osx/buildbot/slave/package_osx10_9-x64/build/deps/srccache/libuv-ecbd6eddfac4940ab8db57c73166a7378563ebd3/src/unix/stream.c:1450
uv_write at /Users/osx/buildbot/slave/package_osx10_9-x64/build/deps/srccache/libuv-ecbd6eddfac4940ab8db57c73166a7378563ebd3/src/unix/stream.c:1475
jl_uv_write at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/jl_uv.c:411
uv_write at ./stream.jl:799
unsafe_write at ./stream.jl:820
unsafe_write at ./io.jl:141
write at ./io.jl:180
unknown function (ip: 0x102c09971)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:175
print; at ./char.jl:0
unknown function (ip: 0x314448adf)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:175
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1394
jl_threading_run at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/threading.c:691
macro expansion; at ./threadingconstructs.jl:46
unknown function (ip: 0x31444888f)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:175
jl_toplevel_eval_in_warn at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/builtins.c:573
eval at ./boot.jl:234
unknown function (ip: 0x102bc2def)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:175
eval_user_input at ./REPL.jl:62
unknown function (ip: 0x314446d16)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:175
macro expansion; at ./REPL.jl:92
unknown function (ip: 0x31443d20f)
jl_call_method_internal at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia_internal.h:175
jl_apply at /Users/osx/buildbot/slave/package_osx10_9-x64/build/src/./julia.h:1394
Allocations: 1683687 (Pool: 1682825; Big: 862); GC: 0
Segmentation fault: 11
@yuyichao yuyichao changed the title segfault when printing to screen from within multithreaded loop Libuv is not thread safe Jul 12, 2016
@yuyichao yuyichao added the domain:multithreading Base.Threads and related functionality label Jul 12, 2016
@andreasnoack
Copy link
Member

If you just want to have something printed from within the threading loop for, say, debugging purposes then you can bypass Libuv with

Threads.@threads for i = 1:10
    ccall(:jl_,Void,(Any,), "this is thread number $(Threads.threadid())")
end

@samuelpowell
Copy link
Member Author

@andreasnoack exactly so, thank you.

@ViralBShah
Copy link
Member

@ranjanan Worth noting this in the threading documentation. This is a natural thing everyone will want to try, and our printing and i/o is not thread safe.

@ViralBShah ViralBShah added the domain:docs This change adds or pertains to documentation label Jul 13, 2016
@yuyichao yuyichao changed the title Libuv is not thread safe Libuv and tasks are not thread safe Aug 30, 2016
@yuyichao yuyichao changed the title Libuv and tasks are not thread safe segfault when printing to screen from within multithreaded loop Aug 30, 2016
@yuyichao
Copy link
Contributor

Dup of #14494

@sbromberger
Copy link
Contributor

sbromberger commented Jul 17, 2017

Just to add to this: sometimes there's unintended I/O; for example, with depwarn. This code will cause segfaults in threads on Julia 0.6 even though there's no explicit output:

julia> Threads.@threads for i = 1:10
       z = abs([1:10;])
       end
WARNING: WARNING: WARNING: WARNING: WARNING:
signal (11): Segmentation fault: 11
while loading no file, in expression starting on line 0
uv__write at /Users/bromberger1/dev/julia/julia6/deps/srccache/libuv-52d72a52cc7ccd570929990f010ed16e2ec604c8/src/unix/stream.c:890
uv_write2 at /Users/bromberger1/dev/julia/julia6/deps/srccache/libuv-52d72a52cc7ccd570929990f010ed16e2ec604c8/src/unix/stream.c:1450
uv_write at /Users/bromberger1/dev/julia/julia6/deps/srccache/libuv-52d72a52cc7ccd570929990f010ed16e2ec604c8/src/unix/stream.c:1475
jl_uv_write at /Users/bromberger1/dev/julia/julia6/src/jl_uv.c:414
uv_write at ./stream.jl:798
unsafe_write at ./stream.jl:832
print at ./strings/io.jl:122 [inlined]
#with_output_color#509 at ./util.jl:404
jl_apply at /Users/bromberger1/dev/julia/julia6/src/./julia.h:1424 [inlined]
jl_f__apply at /Users/bromberger1/dev/julia/julia6/src/builtins.c:426
#with_output_color at ./<missing>:0
jl_apply at /Users/bromberger1/dev/julia/julia6/src/./julia.h:1424 [inlined]
jl_f__apply at /Users/bromberger1/dev/julia/julia6/src/builtins.c:426
abs{T <: Number}(x::AbstractArray{T}) is deprecated, use abs.(x) instead.#print_with_color#510 at ./util.jl:417
jl_apply at /Users/bromberger1/dev/julia/julia6/src/./julia.h:1424 [inlined]
jl_f__apply at /Users/bromberger1/dev/julia/julia6/src/builtins.c:426

(it also had the effect of pegging CPUs at 100% until ^C was issued.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:docs This change adds or pertains to documentation domain:multithreading Base.Threads and related functionality
Projects
None yet
Development

No branches or pull requests

5 participants