コードには 2 つのセクションがあります。
section_a
# some code
section_b
section_bが実行されている場合にのみ、 section_aをブロックする必要があります。section_bにブロックがない場合、section_aは多くのスレッドで実行できます。
section_bの実行が開始されたら、他のスレッドにシグナルを送信して、section_aに入らないようにする(その前に待機する) 必要があります。そして、最後のスレッドが section_a を離れると、section_bを実行する必要があります。
条件付きロック (threading.Condition.acquire()、threading.Condition.release()) を使用して問題を解決する場合、多くのスレッドが同時にsection_aに入るのを許可する方法がわかりません。section_aの前に condition.acquire() を呼び出すと、他のスレッドもブロックされてセクションに入ります。
while True:
condition.acquire() # other threads that would enter point_a can't do that after this acquire()
#section_a, point_a
condition.release()
# another place of a program
while True:
condition.acquire() # I'd like threads can't enter section_a after this acquire, but not after acquire before point_a
#section_b
condition.release()
また、 section_aがスレッドによって実行される場合は、section_bをブロックする必要があります。
正しい構造を教えてください。
すみません、私はマルチスレッドの経験がありません。おそらく、まったく別の構造があります。