Parallel for breaks in SDL application

#1

I am doing my first attempt ever at Julia with multi-threading. I wrote a program to draw a fractal using SDL and SIMD instructions. That works well. To render each frame I just do a loop over all pixels, calculate a value and store the corresponding color in the output image array. Then I attempted to just use Threads.@threads on the loop that goes over the image lines, and I get the error message at the bottom.

Of course multi-threading can be very challenging, but I am surprised since this is an “embarrassingly parallelizable” problem. What can be causing this? Could this be actually related to SDL?

My code is available at https://github.com/nlw0/Juliaplex

fatal: error thrown and no exception handler available.
ErrorException("concurrency violation detected")
rec_backtrace at /home/user/src/julia/src/stackwalk.c:94
record_backtrace at /home/user/src/julia/src/task.c:210 [inlined]
jl_throw at /home/user/src/julia/src/task.c:417
error at ./error.jl:33
assert_havelock at ./condition.jl:20 [inlined]
assert_havelock at ./condition.jl:43 [inlined]
assert_havelock at ./condition.jl:67 [inlined]
notify at ./condition.jl:118
#notify#463 at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
uv_timercb at ./asyncevent.jl:148
jlcapi_uv_timercb_4141 at /home/user/src/julia/usr/lib/julia/sys.so (unknown line)
uv__run_timers at /workspace/srcdir/libuv/src/timer.c:162
uv_run at /workspace/srcdir/libuv/src/unix/core.c:352
jl_task_get_next at /home/user/src/julia/src/partr.c:303
poptaskref at ./task.jl:564
wait at ./task.jl:591
task_done_hook at ./task.jl:327
jl_apply_generic at /home/user/src/julia/src/gf.c:2197
jl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
jl_finish_task at /home/user/src/julia/src/task.c:167
start_task at /home/user/src/julia/src/task.c:593
unknown function (ip: 0xffffffffffffffff)
fatal: error thrown and no exception handler available.
ErrorException("concurrency violation detected")
rec_backtrace at /home/user/src/julia/src/stackwalk.c:94
record_backtrace at /home/user/src/julia/src/task.c:210 [inlined]
jl_throw at /home/user/src/julia/src/task.c:417
error at ./error.jl:33
fatal: error thrown and no exception handler available.
ErrorException("concurrency violation detected")
rec_backtrace at /home/user/src/julia/src/stackwalk.c:94
record_backtrace at /home/user/src/julia/src/task.c:210 [inlined]
jl_throw at /home/user/src/julia/src/task.c:417
assert_havelock at ./condition.jl:20 [inlined]
assert_havelock at ./condition.jl:43 [inlined]
assert_havelock at ./condition.jl:67 [inlined]
notify at ./condition.jl:118
error at ./error.jl:33
#notify#463 at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
uv_timercb at ./asyncevent.jl:148
assert_havelock at ./condition.jl:20 [inlined]
assert_havelock at ./condition.jl:43 [inlined]
assert_havelock at ./condition.jl:67 [inlined]
notify at ./condition.jl:118
jlcapi_uv_timercb_4141 at /home/user/src/julia/usr/lib/julia/sys.so (unknown line)
uv__run_timers at /workspace/srcdir/libuv/src/timer.c:162
uv_run at /workspace/srcdir/libuv/src/unix/core.c:375
jl_task_get_next at /home/user/src/julia/src/partr.c:303
notify_error at ./condition.jl:129 [inlined]
_uv_hook_close at ./asyncevent.jl:132
jl_apply_generic at /home/user/src/julia/src/gf.c:2191
jl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
jl_uv_call_close_callback at /home/user/src/julia/src/jl_uv.c:81 [inlined]
jl_uv_closeHandle at /home/user/src/julia/src/jl_uv.c:100
uv__finish_close at /workspace/srcdir/libuv/src/unix/core.c:279
poptaskref at ./task.jl:564
uv__run_closing_handles at /workspace/srcdir/libuv/src/unix/core.c:293
uv_run at /workspace/srcdir/libuv/src/unix/core.c:363
jl_task_get_next at /home/user/src/julia/src/partr.c:303
wait at ./task.jl:591
task_done_hook at ./task.jl:327
jl_apply_generic at /home/user/src/julia/src/gf.c:2191
poptaskref at ./task.jl:564
jl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
jl_finish_task at /home/user/src/julia/src/task.c:167
start_task at /home/user/src/julia/src/task.c:593
unknown function (ip: 0xffffffffffffffff)
wait at ./task.jl:591
task_done_hook at ./task.jl:327
jl_apply_generic at /home/user/src/julia/src/gf.c:2191
jl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
jl_finish_task at /home/user/src/julia/src/task.c:167
start_task at /home/user/src/julia/src/task.c:593
unknown function (ip: 0xffffffffffffffff)
*** Error in `julia': double free or corruption (!prev): 0x0000555cf7038080 ***
0 Likes

#2

More information. Testing without SDL does seem to work. Also running with the debugger I got this message:

fatal: error thrown and no exception handler available.
ErrorException("concurrency violation detected")
rec_backtrace at /home/user/src/julia/src/stackwalk.c:94
record_backtrace at /home/user/src/julia/src/task.c:210 [inlined]
jl_throw at /home/user/src/julia/src/task.c:417
error at ./error.jl:33
fatal: error thrown and no exception handler available.
ErrorException("concurrency violation detected")
assert_havelock at ./condition.jl:20 [inlined]
assert_havelock at ./condition.jl:43 [inlined]
assert_havelock at ./condition.jl:67 [inlined]
notify at ./condition.jl:118
rec_backtrace at /home/user/src/julia/src/stackwalk.c:94
fatal: error thrown and no exception handler available.
ErrorException("concurrency violation detected")
record_backtrace at /home/user/src/julia/src/task.c:210 [inlined]
jl_throw at /home/user/src/julia/src/task.c:417
#notify#463 at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
uv_timercb at ./asyncevent.jl:148
jlcapi_uv_timercb_4141 at /home/user/src/julia/usr/lib/julia/sys.so (unknown line)
uv__run_timers at /workspace/srcdir/libuv/src/timer.c:162
rec_backtrace at /home/user/src/julia/src/stackwalk.c:94
assert_havelock at ./condition.jl:20 [inlined]
assert_havelock at ./condition.jl:43 [inlined]
assert_havelock at ./condition.jl:67 [inlined]
notify at ./condition.jl:118
uv_run at /workspace/srcdir/libuv/src/unix/core.c:375
jl_task_get_next at /home/user/src/julia/src/partr.c:303
#notify#463 at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
uv_timercb at ./asyncevent.jl:148
jlcapi_uv_timercb_4141 at /home/user/src/julia/usr/lib/julia/sys.so (unknown line)
record_backtrace at /home/user/src/julia/src/task.c:210 [inlined]
jl_throw at /home/user/src/julia/src/task.c:417
poptaskref at ./task.jl:564
uv__run_timers at /workspace/srcdir/libuv/src/timer.c:162
error at ./error.jl:33
uv_run at /workspace/srcdir/libuv/src/unix/core.c:375
wait at ./task.jl:591
assert_havelock at ./condition.jl:20 [inlined]
l_task_get_next at /home/user/src/julia/src/partr.c:303
assert_havelock at ./condition.jl:43 [inlined]
assert_havelock at ./condition.jl:67 [inlined]
notify at ./condition.jl:118
task_done_hook at ./task.jl:327
jl_apply_generic at /home/user/src/julia/src/gf.c:2197
poptaskref at ./task.jl:564
#notify#463 at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
notify at ./condition.jl:116 [inlined]
uv_timercb at ./asyncevent.jl:148
jl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
jl_finish_task at /home/user/src/julia/src/task.c:167
jlcapi_uv_timercb_4141jlcapi_uv_timercb_4141 at /home/user/src/julia/usr/lib/julia/sys.so (unknown line)
task_done_hook at ./task.jl:327
uv__run_timers at /workspace/srcdir/libuv/src/timer.c:162
start_task at /home/user/src/julia/src/task.c:593
jl_apply_generic at /home/user/src/julia/src/gf.c:2197
unknown function (ip: 0xffffffffffffffff)
jl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
jl_finish_task at /home/user/src/julia/src/task.c:167




start_task at /home/user/src/julia/src/task.c:593
unknown function (ip: 0xffffffffffffffff)
uv_run at /workspace/srcdir/libuv/src/unix/core.c:375
jl_task_get_next at /home/user/src/julia/src/partr.c:303

signal (11): Segmentation fault

signal (11): Segmentation fault
in expression starting at /home/user/src/jldemo/juliademo.jl:126
in expression starting at /home/user/src/jldemo/juliademo.jl:126
poptaskref at ./task.jl:564
wait at ./task.jl:591
task_done_hook at ./task.jl:327
jl_apply_generic at /home/user/src/julia/src/gf.c:2197
_PyObject_Malloc at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
jl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
jl_finish_task at /home/user/src/julia/src/task.c:167
_PyObject_Malloc at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyUnicode_New at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
)
PyUnicode_New at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
unknown function (ip: 0xffffffffffffffff)

signal (11): Segmentation fault
in expression starting at /home/user/src/jldemo/juliademo.jl:126
_PyUnicodeWriter_/home/user/.julia/c/home/user/.julia/conda/3/lib/libpython3.7m.so
.
_PyUnicodeWriter_/home/user/.julia/c/home/user/.julia/conda/3/lib/libpython3.7m.so
_PyUnicodeWriter_/home/user/.julia/c/home/user/.julia/conda/3/lib/libpython3.7m.so
.
PyUnicode_DecodeUTF8Stateful at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
_PyUnicodeWriter_PrepareInternal at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyUnicode_DecodeUTF8Stateful at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
_PyUnicode_FromId at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
_PyObject_SetAttrId at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
)
_PyObject_SetAttrId at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyObject_CallMethod at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyUnicode_New at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
iobase_finalize at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown lineiobase_finalize at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
iobase_finalize at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
 (unknown line)
PyFile_WriteObject at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyErr_WriteUnraisable at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyUnicode_DecodeUTF8Stateful at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
Py_FinalizeEx at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
_PyUnicode_FromId at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
_PyObject_SetAttrId at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
_PyObject_SetAttrId at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
)
PyObject_CallFinalizerFromDealloc at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
jl_apply_generic at /home/user/src/julia/src/gf.c:2197
iobase_finalize at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
ine)
iobase_finalize at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
dict_dealloc.lto_priv.383 at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
_atexit at ./initdefs.jl:309
ct at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyObject_CallFinalizer at /hoPyObject_CallFinalizer at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
_PyEval_EvalFrameDefault at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyObject_CallFinalizerFromDealloc at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unkPyObject_CallFinalizerFromDealloc at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyObject_CallFinalizerFromDealloc at /home/user/.julia/textiowrapper_dealloc at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
ine)
textiowrapper_dealloc at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
dict_dealloc.lto_priv.383 at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
jl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
/lib/libpython3.7m.so.1.0 (unknown line)
jl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
/lib/libpython3.7m.so.1.0 (unknowjl_apply at /home/user/src/julia/src/julia.h:1604 [inlined]
jl_atexit_hook at /home/user/src/julia/src/init.c:240
_PyEval_EvalFrameDefault at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
jl_exit at /home/user/src/julia/src/jl_uv.c:613
function_code_fastcall at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
_PyFunction_FastCallDict at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
function_code_fastcall at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
PyObject_CallMethodId at /home/user/.julia/conda/3/li_PyFunction_FastCallDict at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line_PyFunction_FastCallDict at /home/user/.julia/conda/3/lib/libpython3.7m.so.1.0 (unknown line)
Segmentation fault (core dumped)
0 Likes

#3

I’m really curious if anyone has any thoughts especially because the last error messages seem to involve some Python stuff and I have absolutely no clue where this might be coming from.

I am also having problems with @btime running this parallel loop (Running a function with multiple threads inside @btime never ends). It seems to be something wrong happening after all the computations are over.

Should I start a ticket on GitHub perhaps? I didn’t want to do this before I had a better idea of what could be causing this problem. I would gladly try to debug it, but I would definitely need some directions too.

0 Likes

#4

I am getting the error even without SDL, this small code produces it, even though it only happens if I’m running Julia withing Emacs. On the command line it works. Would be nice to know if anyone can reproduce this.

using Base.Threads

function runs(n)
    a = zeros(n)
    @threads for j in 1:n
        a[n] += n^2
    end
    sum(a)
end

println(runs(100))
0 Likes

#5

Apparently it’s just this same issue https://github.com/JuliaLang/julia/issues/31702

0 Likes