|
360 | 360 | end |
361 | 361 | end |
362 | 362 |
|
| 363 | +@testset "io_thread" begin |
| 364 | + function io_thread_test() |
| 365 | + # This test creates a thread that does IO and then blocks the main julia thread |
| 366 | + # This test hangs if you don't spawn an IO thread. |
| 367 | + # It hanging or not is technically a race but I haven't seen julia win that race yet. |
| 368 | + cmd = """ |
| 369 | + Base.Experimental.make_io_thread() |
| 370 | + function callback()::Cvoid |
| 371 | + println("Running a command") |
| 372 | + run(`echo 42`) |
| 373 | + return |
| 374 | + end |
| 375 | + function call_on_thread(callback::Ptr{Nothing}) |
| 376 | + tid = UInt[0] |
| 377 | + threadwork = @cfunction function(arg::Ptr{Cvoid}) |
| 378 | + current_task().donenotify = Base.ThreadSynchronizer() |
| 379 | + Base.errormonitor(current_task()) |
| 380 | + println("Calling Julia from thread") |
| 381 | + ccall(arg, Cvoid, ()) |
| 382 | + nothing |
| 383 | + end Cvoid (Ptr{Cvoid},) |
| 384 | + err = @ccall uv_thread_create(tid::Ptr{UInt}, threadwork::Ptr{Cvoid}, callback::Ptr{Cvoid})::Cint |
| 385 | + err == 0 || Base.uv_error("uv_thread_create", err) |
| 386 | + gc_state = @ccall jl_gc_safe_enter()::Int8 |
| 387 | + err = @ccall uv_thread_join(tid::Ptr{UInt})::Cint |
| 388 | + @ccall jl_gc_safe_leave(gc_state::Int8)::Cvoid |
| 389 | + err == 0 || Base.uv_error("uv_thread_join", err) |
| 390 | + return |
| 391 | + end |
| 392 | + function main() |
| 393 | + callback_ptr = @cfunction(callback, Cvoid, ()) |
| 394 | + call_on_thread(callback_ptr) |
| 395 | + println("Done") |
| 396 | + end |
| 397 | + main() |
| 398 | +
|
| 399 | + """ |
| 400 | + proc = run(pipeline(`$(Base.julia_cmd()) -e $cmd`), wait=false) |
| 401 | + t = Timer(60) do t; kill(proc); end; |
| 402 | + @test success(proc) |
| 403 | + close(t) |
| 404 | + return true |
| 405 | + end |
| 406 | + @test io_thread_test() |
| 407 | +end |
| 408 | + |
363 | 409 | # Make sure default number of BLAS threads respects CPU affinity: issue #55572. |
364 | 410 | @testset "LinearAlgebra number of default threads" begin |
365 | 411 | if AFFINITY_SUPPORTED |
|
0 commit comments