mirror of
https://github.com/onyx-and-iris/voicemeeter-rb.git
synced 2024-11-25 11:20:48 +00:00
use thread local variable :running
and safe navigation to terminate producer thread
This commit is contained in:
parent
5292ac6bf1
commit
c5faec40ea
@ -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
|
||||||
|
Loading…
Reference in New Issue
Block a user