17

ですから、これは宿題の問題だと言って始めましょう。私の教授は、Java で 1 回、別の言語で 1 回書かなければならない課題を私たちに与えました。少なくとも少しは慣れているので、2 つ目の言語として Python を選びました。プログラムは次のように動作する必要があります。

start the main method/thread, which we will call parent
start thread child 1 from the parent
start thread grandchild from thread child 1
start thread child 2 from the parent
print grandchild from the grandchild thread
print child 2 from the child 2 thread
print child 1 from the child 1 thread
print parent from the main method/parent thread

これらのことは、この順序で行う必要があります。これらのことが発生する方法を整理するために、CountDownLatch を使用して Java でこれを行うコードを作成しました。ただし、Python では同様のメカニズムは見当たりませんでした (ただし、Java ほど Python には詳しくありません)。それが何と呼ばれているのかわからないので、おそらく私が見つけることができない同様のメカニズムはありますか?

4

3 に答える 3

0

モジュールのSemaphoreまたはConditionクラスを見てください。threading

于 2012-04-19T21:37:05.000 に答える