-
Notifications
You must be signed in to change notification settings - Fork 221
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
lock failing in multithreaded plan_fft() #1921
Labels
bug
Something isn't working
Comments
I've also seen this error as well:
|
MWE: struct Cache{K,V}
handles::Dict{K,V}
lock::ReentrantLock
function Cache{K,V}() where {K,V}
return new{K,V}(Dict{K,V}(), ReentrantLock())
end
end
macro safe_lock(l, ex)
quote
GC.enable(false)
lock($(esc(l)))
try
$(esc(ex))
finally
unlock($(esc(l)))
GC.enable(true)
end
end
end
# get or create value
function Base.pop!(ctor::Function, cache::Cache{K,V}, key) where {K,V}
# lookup
function check_cache()
@safe_lock cache.lock begin
if !haskey(cache.handles, key)
nothing
else
cache.handles[key]
end
end
end
handle = check_cache()
if handle === nothing
GC.gc(false)
handle = check_cache()
end
# create
if handle === nothing
handle = ctor()::V
end
return handle
end
# put in cache or destroy value
function Base.push!(dtor::Function, cache::Cache{K,V}, key::K, handle::V) where {K,V}
# cache
should_destroy = @safe_lock cache.lock begin
if haskey(cache.handles, key)
true
else
cache.handles[key] = handle
false
end
end
# destroy
if should_destroy
dtor(handle)
end
return
end
const handles = Cache{Int, Int}()
mutable struct Foo
handle
function Foo()
x = rand(1:100)
handle = pop!(handles, x) do
x
end
obj = new(handle)
finalizer(obj) do _
push!(handles, handle, handle) do _
# do nothing
end
end
end
end
function test()
try
for nn=1:10
tids = [Threads.@spawn Foo() for nn=1:10]
while !all(istaskdone.(tids))
yield()
end
end
catch e
error(e)
end
end
while true
test()
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The CUDA.CUFFT.plan_fft!() appears to have a thread locking issue:
generates:
Discourse thread:
https://discourse.julialang.org/t/is-cuda-jl-and-fftw-threadsafe/99219/4?u=jpdoane
version info:
The text was updated successfully, but these errors were encountered: