juliamatlab / mexjulia

embedding Julia in the MATLAB process.
MIT License
52 stars 14 forks source link

Segfaults in Jl.call on Ubuntu #3

Closed KristofferC closed 9 years ago

KristofferC commented 9 years ago

Running x = rand(10^6,1) and repeatedly calling Jl.call(sin, x) segfaults after a while. This is with MATLAB 8.5 and julia 4.0 rc4 on Ubuntu.

fatal: error thrown and no exception handler available.
ReadOnlyMemoryError()
rec_backtrace at /home/kristoffer/Downloads/julia-e9c9c92d19/lib/julia/libjulia.so (unknown line)
jl_throw at /home/kristoffer/Downloads/julia-e9c9c92d19/lib/julia/libjulia.so (unknown line)
jl_exit_on_sigint at /home/kristoffer/Downloads/julia-e9c9c92d19/lib/julia/libjulia.so (unknown line)
unknown function (ip: 0x7f04efa21340)
unknown function (ip: 0x7f04c5012dcf)
unknown function (ip: 0x7f04c5006350)
unknown function (ip: 0x7f04c5006350)
unknown function (ip: 0x7f04c5006058)
unknown function (ip: 0x7f04c5006058)
unknown function (ip: 0x7f04c5006350)
unknown function (ip: 0x7f04c5006350)
unknown function (ip: 0x7f04c5006058)
unknown function (ip: 0x7f04c5006058)
unknown function (ip: 0x7f04c5006058)
unknown function (ip: 0x7f04c5006058)
unknown function (ip: 0x7f04c5006058)
unknown function (ip: 0x7f04c54c6da0)
Opening log file:  /home/kristoffer/java.log.2999
$ 
[1]+  Segmentation fault      (core dumped) matlab
twadleigh commented 9 years ago

I tried this test script on my machine:

x = rand(10^6,1);

for k = 1:1000000
  Jl.call('sin',x);
end

and wasn't able to generate a failure on my windows machine.

This julia-users thread is probably relevant: https://groups.google.com/forum/#!searchin/julia-users/matlab$20mex/julia-users/yV4rsNokZH4/5yvrflqivdcJ

twadleigh commented 9 years ago

In that thread, @JeffBezanson says:

This line will do it:

jl_options.handle_signals = JL_OPTIONS_HANDLE_SIGNALS_OFF; 

jl_options is DLLEXPORTed, and both it and its type are in julia.h.

The OP says it worked for them, so I will add this to the init block in jlcall.cpp.

twadleigh commented 9 years ago

@KristofferC: do a pull, delete the old jlcall mex function, and give this patch a try.

bermanmaxim commented 9 years ago

I didn't try this before the pull, but for reference I don't see any segfault executing the sin many times, on ubuntu.

twadleigh commented 9 years ago

OK, I'll close this. Please request to reopen it if you see it again.

KristofferC commented 9 years ago

I will test again tomorrow when I get back to my work computer where I had the segfaults.

KristofferC commented 9 years ago

No segfaults here anymore. Great!