Skip to content

Commit

Permalink
Avoid atexit errors by at least checking if the queue is still valid.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Jan 24, 2025
1 parent 4be457c commit a17c34b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/cl/cmdqueue.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

mutable struct CmdQueue <: CLObject
const id::cl_command_queue
Base.@atomic valid::Bool

function CmdQueue(q_id::cl_command_queue; retain::Bool=false)
q = new(q_id)
q = new(q_id, true)
retain && clRetainCommandQueue(q)
finalizer(q) do _
clReleaseCommandQueue(q)
Base.@atomic q.valid = false
clReleaseCommandQueue(q)
end
return q
end
Expand Down
4 changes: 3 additions & 1 deletion src/memory.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@ function free(managed::Managed{<:cl.AbstractMemory})
# application to make sure that enqueued commands that use svm_pointer have finished
# before freeing svm_pointer". USM has `clMemBlockingFreeINTEL`, but by doing the
# synchronization ourselves we provide more opportunity for concurrent execution.
synchronize(managed)
if managed.queue.valid
synchronize(managed)
end

if mem isa cl.SharedVirtualMemory
cl.svm_free(mem)
Expand Down

0 comments on commit a17c34b

Please sign in to comment.