abalfazl hossein wrote:
output:
run:
10 The thread that is running is Amir
But thread hossein does not show anything and this program does not stop, Why?
abalfazl hossein wrote:
This program work well.
abalfazl hossein wrote:
These is question. At this line, run method,runs:
How can I be sure that notify(); would not be crossed before call this line:
abalfazl hossein wrote:Thanks Sir, But you didn't answer my question.
now use those blocks to protect the variables that track the state.
abalfazl hossein wrote:
now use those blocks to protect the variables that track the state.
I've read tutorials
http://www.avajava.com/tutorials/lessons/how-do-i-use-the-wait-and-notify-methods.html
But they didn't use state variable. May you show me how to use by an example?
abalfazl hossein wrote:
I've read tutorials
http://www.avajava.com/tutorials/lessons/how-do-i-use-the-wait-and-notify-methods.html
But they didn't use state variable. May you show me how to use by an example?
There are certain practices that you should always follow with condition variables (aka the wait/notify mechanism)... First, you should never do a "blind" wait -- always confirm that you need to wait before you actually call wait(). Second, you should never assume that the state is correct upon return from wait -- always confirm that you are able to continue upon return.
abalfazl hossein wrote:
Two sentences make me think, always confirm that you are able to continue upon return, always confirm that you are able to continue upon return.
Sir, May you give me simple example about these sentences? I appreciate Sir.
abalfazl hossein wrote:
I also change the code of another example:
abalfazl hossein wrote:
I add a flag, Because I want be sure that for loop finished its job then hossein thread finishes its job.I used a static member in order this variable could accessed in other class easily,Just by the name of class. Other than that I had to use getter/setter.I wanted Player2 class knows what happened in Player1.
Henry Wong wrote:
abalfazl hossein wrote:
I also change the code of another example:
There is nothing in this example that implements what was discussed in this topic. This example have the same issue that the original example has.
Interestingly, this example has another issue. It is using the thread object as the notification object, so it will get an extraneous notification (due to the fact that the core library also use the same object). So, arguably, this example is worst than the original. On the other hand, this is a case of two wrongs does make a right -- the extraneous notification may actually help make the first issue go away....
Henry
abalfazl hossein wrote:Then Please guide me what is necessary to change this code?
He repaced his skull with glass. So you can see his brain. Kinda like this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|