-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Grisu (floating point printing) not thread-safe #25727
Comments
Discovered by @RCS-77. |
String interpolation is fine, the global buffer for floating point formatting in grisu is not. |
Ah, thanks for the clarification, @yuyichao! |
Could we simply do something like const DIGITS = [Vector{UInt8}(uninitialized, 309+17) for _ in 1:Base.Threads.nthreads()]
[...]
function grisu(v::AbstractFloat,mode,requested_digits,buffer=DIGITS[Base.Threads.threadid()],bignums=BIGNUMS)
if signbit(v)
[...]
...
in "grisu.jl"? |
We have more allocation elision for buffers now, so we should probably just move it inside the function. The one wrinkle is that I believe this buffer is shared across quite a number of large functions, so our local escape analysis is probably not powerful enough. I wonder whether we can just start doing inter-procedural escape analysis in inference. |
Hopefully soon. I'm not sure if that'll work for our Arrays right now as well. Might need to change this to a |
Yes, I think the uses in grisu are going to be very hard to optimize automatically. |
Since it's a fixed size buffer - could we simply stack allocate 309+17 bytes and get the pointer - or does it have to be a real Julia array? |
If stack allocation is not possible and allocation elision won't work in this scenario yet, could we adopt the "one array per thread" approach for now, to get thread safety? Maybe also as a backport to v0.6? Non-threadsafe floating point formatting is kinda painful to work around ... |
Please keep in mind, that also |
Thanks, @stevengj ! |
It looks like string interpolation is currently not threadsafe. Running the following script "string_interpolation_threadsafe_test.jl"
via
with Julia 0.7.0-DEV.3551 (x86_64, official binary, on Ubuntu 16.04) results in
test_without_mutex_repeated()
sometimes ends in a segfault.The same problem occurs with Julia v0.6.
As string interpolation may be used deep inside a third-party function/dependency, and is therefore hard to control/fence, this is a serious problem when writing multi-threaded code.
The text was updated successfully, but these errors were encountered: