Is there any reason why notifyAll should only wake one of a couple of threads waiting on some monitor?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Thomas_Schwarzfischer
Posted On:   Friday, June 7, 2002 02:48 PM

In my application I intended to run a thread acting as a trigger for some other threads. As expected, all these task go for sleep when coming across the wait call in wait_for_trigger(). However, when the trigger thread subsequently calls notifyAll() on the lock object, only one of the threads wakes up... What am I missing here? Thanks a lot for any answers. public void trigger_simulation_threads() { synchronized (lock) { while (!all_sim_threads_ready()) { try { m_ready = true; lock.wait(); } catch (InterruptedException e) { } } reset_ready(); lock.notifyAll(); } } public void wait_for_   More>>

In my application I intended to run a thread acting as a trigger for some other threads. As expected, all these
task go for sleep when coming across the wait call in
wait_for_trigger(). However, when the trigger thread
subsequently calls notifyAll() on the lock object, only
one of the threads wakes up... What am I missing here?
Thanks a lot for any answers.


			
public void trigger_simulation_threads() {
synchronized (lock) {
while (!all_sim_threads_ready()) {
try {
m_ready = true;
lock.wait();
} catch (InterruptedException e) {
}
}
reset_ready();
lock.notifyAll();
}
}

public void wait_for_trigger(SimulationThread st) {
synchronized (lock) {
while (!m_ready) {
try {
st.m_ready = true;
lock.wait();
} catch (InterruptedException e) {
}
}
m_ready = false;
lock.notify();
}
}
   <<Less
About | Sitemap | Contact