Today, when I was looping through multithreading, I found a problem, that is, when I looped through multithreading, there was a deviation between the value passed in and the value received by the method, why??? As follows:
Then, I searched from the Internet, and I found a solution, why didn't it appear before??? Or is it not found?????
Finally, write a test demo as follows:
I found that test1 has many errors, test2 has not had this problem,
The int type is a value type, and string is a special reference type, so this problem should not occur.
Until now, I don't know why this is the case, this article is dedicated to people who often operate multithreading。。。。。。
|