Skip to content

Creating non-sticky tasks in a @threads loop causes "Unlocking a lock in a different thread" #31614

@vchuravy

Description

@vchuravy

After fixing #31613 my mean test-code (enquing work from tid==1 and then servicing it else on the other worker threads), fails with a julia/src/locks.h:152: jl_mutex_unlock_nogc: Assertion lock->owner == jl_thread_self() && "Unlocking a lock in a different thread."'

chaos.jl

 Base.Threads.@threads for i in 1:Base.Threads.nthreads()
           if Base.Threads.threadid() == 1
             tasks = Task[]
             for i in 1:10
               t = Task(()->println("tid: ", Base.Threads.threadid()))
               t.sticky = false
               push!(tasks, t)
               schedule(t)
             end
             Base.sync_end(tasks)
           end
        end

To cite Jeff: The only parallel program one would ever want to execute is to print the threadid.

➜  julia ./julia chaos.jl
tid: 1julia: /home/vchuravy/src/julia/src/locks.h:152: jl_mutex_unlock_nogc: Assertion `lock->owner == jl_thread_self() && "Unlocking a lock in a different thread."' failed.

signal (6): Aborted
in expression starting at /home/vchuravy/builds/julia/chaos.jl:1
gsignal at /usr/lib/libc.so.6 (unknown line)
abort at /usr/lib/libc.so.6 (unknown line)
__assert_fail_base.cold.0 at /usr/lib/libc.so.6 (unknown line)
__assert_fail at /usr/lib/libc.so.6 (unknown line)
jl_mutex_unlock_nogc at /home/vchuravy/src/julia/src/locks.h:151 [inlined]
jl_eh_restore_state at /home/vchuravy/src/julia/src/rtutils.c:257
uv_write at ./stream.jl:875
unsafe_write at ./stream.jl:923
macro expansion at ./gcutils.jl:87 [inlined]
write at ./strings/io.jl:177 [inlined]
show at ./show.jl:586 [inlined]
print at ./strings/io.jl:37
unknown function (ip: 0x7f1074afa367)
jl_apply_generic at /home/vchuravy/src/julia/src/gf.c:2197
print at ./strings/io.jl:48
jl_apply_generic at /home/vchuravy/src/julia/src/gf.c:2197
jl_apply at /home/vchuravy/src/julia/src/julia.h:1604 [inlined]
jl_f__apply at /home/vchuravy/src/julia/src/builtins.c:563
println at ./strings/io.jl:75
jl_apply_generic at /home/vchuravy/src/julia/src/gf.c:2197
println at ./coreio.jl:4
unknown function (ip: 0x7f1074af9997)
jl_apply_generic at /home/vchuravy/src/julia/src/gf.c:2197
#3 at /home/vchuravy/builds/julia/chaos.jl:5
jl_apply_generic at /home/vchuravy/src/julia/src/gf.c:2197
jl_apply at /home/vchuravy/src/julia/src/julia.h:1604 [inlined]
start_task at /home/vchuravy/src/julia/src/task.c:583
unknown function (ip: 0xffffffffffffffff)
Allocations: 177483 (Pool: 177412; Big: 71); GC: 0
fish: “./julia chaos.jl” terminated by signal SIGABRT (Abort)

Metadata

Metadata

Assignees

No one assigned

    Labels

    multithreadingBase.Threads and related functionality

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions