This topic has been archived. It cannot be replied.
-
工作学习 / IT技术讨论 / If 2 threads are accessing , say 1 read and 1 write, same member variable(not synchronized) at same time, what would happen? would a exception be thrown? If so, what exception would be thrown? If not,the worst case would be the variable value would be totally out-of-order, am I right? Thanks.
-tongcd(Rock Your Body);
2004-7-12
{93}
(#1799135@0)
-
depend on if it is an atomic operation. if the variable is shorter than the "int" (4 bytes in 32 bit cpu or 8 bytes in 64 bits cpu), it should be ok.if it is longer then the "int" or it is an item of structure which is packet, and longer than 1 byte ,there is the asychronizing problem.
-eagle_no1(瞎起哄);
2004-7-12
{141}
(#1799153@0)
-
wow, you really know something. thanks.
-tongcd(Rock Your Body);
2004-7-13
(#1800468@0)
-
In Java, i remember that only long and double will cause the problem(not exception), the others is fine(atomic operation).
-xanada(㊣流水);
2004-7-13
(#1800566@0)
-
No exception at all.
-oceanwater(灌水日月长);
2004-7-13
(#1800530@0)
-
No exception is sure. Any furthur conclusion is assumption.
-pleased(please);
2004-7-14
(#1801410@0)
-
这种做法从计算机的角度上看绝对不会有问题。对于你说的数据会不会被破坏,这完全取决于你如何定义这个破坏。这个问题不需要从计算机的角度去考虑,在书本里讲多线程时都用的银行帐户转帐来解释。
-oceanwater(灌水日月长);
2004-7-14
(#1801831@0)
-
I am not sure if this is allowed in Java, which does have an exception handling this kind of situation. Anyone can clearify?
-orange0(桔子);
2004-7-14
(#1801798@0)
-
#1800530
-xanada(㊣流水);
2004-7-14
(#1801828@0)