Home > Back-end >  If A and B have two threads, A call setValue method first, and then call the getValue method B, then
If A and B have two threads, A call setValue method first, and then call the getValue method B, then

Time:03-13

Private volatile int value=https://bbs.csdn.net/topics/0;
Public void setValue (int value) {
This value=https://bbs.csdn.net/topics/value;
}
Public int getValue () {
Return this. The value;
}
If A and B have two threads, A call setValue method first, and then call the getValue method B, then B threads execute () method returns the result of is what?
I'm still not sure, reorder volatile banned within A thread code, does not ensure thread B by the end of A thread to execute later, in the execution thread scheduling may occur at any time

CodePudding user response:

Put a thread priority setting into higher than b if I can solve

CodePudding user response:

I remember the teacher said, we also tested, weight is very small
  • Related