Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing Params thru wait/notify  RSS feed

 
Siegfried Heintze
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have several threads performing this code:
public class Animator extends Thread{
public void run() {
for(int ii = 0; ii < 16; ii++)try{
synchronized(m_c){try{
m_c.m_x = ii;
m_c.m_id = m_id;
m_c.wait();
The problem is that I now discover that multiple threads can enter the synchronized block so the two parameters I'm trying to pass only belong to the most recent thread! I only want to pass parameters from the thread selected by notify. How do I implement that?
Thanks much!
Siegfried
 
Jerry Pulley
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Siegfried;
When a waiting thread is notified it continues execution where it left off, immediately after the call to <code>wait</code>. You could set the values after the call instead of before it.
jply
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!