私は非同期スレッドマネージャーを実装していて、スレッドへの参照を渡したいのですが、そこで彼の作業の結果を保存する必要があります。そして、すべてのスレッドが終了したら、すべての結果を処理します。
私が必要としているのは、「参照」の操作方法を知ることです。
変数result
(またはhash[:result1]
)があると仮定して、次のようにスレッドに渡します
def test_func
return 777;
end
def thread_start(result)
Thread.new do
result = test_func;
end
end
そして私が欲しいのは次の結果を得ることです
result = 555
thread_start(result);
#thread_wait_logic_there
result == 777; #=> true
hash = {:res1 => 555};
thread_start(hash[:res1])
#thread_wait_logic_there
hash[:res1]==777 #=> true
コードを機能させるには、コードを何に変更する必要がありますか?
Rubyのバージョンは1.9.3です