Skip to content
This repository has been archived by the owner on Mar 12, 2021. It is now read-only.

Thread safety fixes. #621

Merged
merged 1 commit into from
Mar 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions src/CuArrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,30 @@ fail to check whether CUDA is functional, actual use of functionality might warn
"""
function functional(show_reason::Bool=false)
if configured[] === nothing
configured[] = false
if __configure__(show_reason)
configured[] = true
__runtime_init__()
end
_functional(show_reason)
end
configured[]
end

const configure_lock = ReentrantLock()
@noinline function _functional(show_reason::Bool=false)
lock(configure_lock) do
if configured[] === nothing
if __configure__(show_reason)
configured[] = true
try
__runtime_init__()
catch
configured[] = false
rethrow()
end
else
configured[] = false
end
end
end
end

# macro to guard code that only can run after the package has successfully initialized
macro after_init(ex)
quote
Expand Down