• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

wait() and notify() in K&B 5.0

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from K&B 5.0 book, pg. 720


Immediately after b.start (line 6), is it guaranteed that ThreadA will continue its execution? Could it be that ThreadB will execute its run() method first?

If I understand correctly, there is no guarantee which one goes first. Help?


Buhi

(modofied to indicate K&B 5.0)
[ July 28, 2006: Message edited by: Barry Gaunt ]
 
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

If I understand correctly, there is no guarantee which one goes first. Help?



Yes. You understood correctly.

Henry
 
Buhi Mume
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
O oh... does this mean the book explanation (on page 721) is wrong?


As soon as line 4 calls the start() method, ThreadA will continue
with the next line of code in its own class, ...



If it is wrong, how to correct it?
 
Henry Wong
author
Posts: 23959
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Buhi Mume:
O oh... does this mean the book explanation (on page 721) is wrong?

If it is wrong, how to correct it?



I don't have enough information to determine the content of the statement, but thread A does continue with the next line of code in its own class. Now, whether it will do it before thread B starts executing the run() method -- that is not guarranteed.

Henry
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.

The book (p. 529 in 1.4 book) fails to point out this problem.

I guess the example is very basic, so as to not overwhelm the reader.

In the following book example, both threads are in an infinite loop. In this case, it doesn't matter which thread gets the lock first. If the notifying thread notifies the other thread before it starts waiting, it will notify it again the next time through the loop.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic