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

Commit 89cd08f

Browse files
committed
Threadsafe configuration.
1 parent aa2f532 commit 89cd08f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/CuArrays.jl

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,30 @@ fail to check whether CUDA is functional, actual use of functionality might warn
3333
"""
3434
function functional(show_reason::Bool=false)
3535
if configured[] === nothing
36-
configured[] = false
37-
if __configure__(show_reason)
38-
configured[] = true
39-
__runtime_init__()
40-
end
36+
_functional(show_reason)
4137
end
4238
configured[]
4339
end
4440

41+
const configure_lock = ReentrantLock()
42+
@noinline function _functional(show_reason::Bool=false)
43+
lock(configure_lock) do
44+
if configured[] === nothing
45+
if __configure__(show_reason)
46+
configured[] = true
47+
try
48+
__runtime_init__()
49+
catch
50+
configured[] = false
51+
rethrow()
52+
end
53+
else
54+
configured[] = false
55+
end
56+
end
57+
end
58+
end
59+
4560
# macro to guard code that only can run after the package has successfully initialized
4661
macro after_init(ex)
4762
quote

0 commit comments

Comments
 (0)