6
Ayrı bir iş parçacığını başka bir iş parçacığı içinden nasıl başlatırım ve durdururum?Ruby'nin Başlatma ve Durdurma Konuları
loop_a_stopped = true
loop_a = Thread.new do
loop do
Thread.stop if loop_a_stopped
# Do stuff
sleep 3
end
end
loop_b = Thread.new do
loop do
response = ask("> ")
case response.strip.downcase
when "start"
loop_a_stopped = false
loop_a.run
when "stop"
loop_a_stopped = true
when "exit"
break
end
end
end
loop_a.join
loop_b.join
Ahh, bu çok daha anlamlı, teşekkürler. Yine de, ilk kez ne gibi merak ettim, 'STDOUT.sync = true' için. Yine de anlayacağım. – RyanScottLewis
Hm, 'gets' yönteminin çalışması durduruyor. Bununla n'aber? – RyanScottLewis
Yukarıdaki kodla ilgili sorun yok gibi görünüyor. Bunu sorunsuzca halledebilirim. Loop_a'da ne yaptığınızdan şüpheleniyorum (# Do şeyler) loop_a'yı durdurabilir. – bryantsai