I am in this scenario: at a certain point, the main thread need to wait until another thread is started(alive). How can I notify the main thread?
I do not want to write a loop and keep the main thread busy waiting. Thanks a lot.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use
threading.Semaphorewhere your main thread will callacquireafter calling start on the second thread. When the second thread is started to the point you want it will callreleaseon the same semaphore.If the second thread calls
releasefirst then the main thread will return from theacquireimmediately. If the main thread callsacquirefirst then it will block until the second thread callsrelease.Use
threading.Conditionwhere a single condition variable is made available to the main thread and the second thread. The main thread can thenwaiton the variable after it has started the second thread. When the second thread is up it can change the variable and then issue anotifyon it.