use thread local variable :running

and safe navigation to terminate producer thread
This commit is contained in:
onyx-and-iris 2023-08-05 23:08:21 +01:00
parent 5292ac6bf1
commit c5faec40ea

View File

@ -9,10 +9,10 @@ module Voicemeeter
private private
def init_producer(que) def init_producer(que)
@running = true @producer = Thread.new do
Thread.new do
Thread.current.name = "producer" Thread.current.name = "producer"
while @running Thread.current[:running] = true
while Thread.current[:running]
que << :pdirty if event.pdirty que << :pdirty if event.pdirty
que << :mdirty if event.mdirty que << :mdirty if event.mdirty
que << :midi if event.midi que << :midi if event.midi
@ -20,7 +20,7 @@ module Voicemeeter
sleep(@ratelimit) sleep(@ratelimit)
end end
logger.debug "closing #{Thread.current.name} thread" logger.debug "closing #{Thread.current.name} thread"
que << @running que << Thread.current[:running]
end end
end end
@ -55,7 +55,10 @@ module Voicemeeter
end end
def end_event_threads def end_event_threads
@running = false if @producer&.alive? # safe navigation
@producer[:running] = false
@producer.join
end
end end
end end
end end