Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use ThreadGroup to manage input threads. Fixed thread-stopping logic …

…(if thread was blocked on read, would not stop properly).
  • Loading branch information...
commit 0b7489ca42ec08198b009295da6ca4d47a1f571f 1 parent 2c2a525
Jim Menard authored
5 TODO.rdoc
View
@@ -28,11 +28,6 @@
* "Are you sure?" on quit? --- but I hate that.
-* Should each input get its own thread?
-
-* Is UniMIDI gets_data blocking? If so, we'll definitely need to create a
- new thread for each instrument.
-
* Programmable MIDI messages?
* See list of features at http://jimmenard.com/projects/keymaster/
22 lib/patchmaster/patchmaster.rb
View
@@ -88,25 +88,31 @@ def start(init_cursor = true)
end
@curr_patch.start if @curr_patch
- @running = true
+ @input_threads = ThreadGroup.new
@inputs.values.each do |input|
- Thread.new(input) do |instrument|
- loop do
- break unless @running
- instrument.process_messages
- end
+ t = Thread.new(input) do |instrument|
+ loop { instrument.process_messages }
end
+ @input_threads.add(t)
+ debug("#{Time.now} Thread #{t} started")
end
+ @input_threads.enclose
end
# Stops the MIDI input threads.
def stop
- @running = false
+ if @input_threads
+ @input_threads.list.each do |t|
+ Thread.kill(t)
+ debug("#{Time.now} Thread #{t} stopped")
+ end
+ @input_threads = nil
+ end
@curr_patch.stop if @curr_patch
end
def running?
- @running
+ @input_threads
end
def next_song
2  test/patchmaster_test.rb
View
@@ -26,7 +26,7 @@ def test_start
end
def test_running
- assert @pm.instance_variable_get(:@running)
+ assert @pm.running?
assert_only_curr_patch_running
end
Please sign in to comment.
Something went wrong with that request. Please try again.