17.11
Example: Out of Order Writes
THREADS AND LOCKS
The total set of actions may be pictured as follows:
to
 thread
main memory
fro
 thread
read
a
read
b
lock
 class
SynchSimple
load
a
load
b
assign
a
use
a
assign
b
use
b
store
a
store
b
printing
write
a
write
b
unlock
 class
SynchSimple
Here an arrow from action
A
 to action
B
 indicates that
A
 must precede
B
.
In what order may the actions by the main memory occur? Note that the rules
do not require that
write
a
 occur before
write
b
; neither do they require that
read
a
occur before
read
b
. Also, even though method
to
 is
synchronized
, method
fro
is not
synchronized
, so there is nothing to prevent the
read
 actions from occur 
ring between the
lock
 and
unlock
 actions. (The point is that declaring one method
synchronized
 does not of itself make that method behave as if it were atomic.)
As a result, the method
fro
 could still obtain either
1
 or
3
 for the value of
a
,
and independently could obtain either
2
 or
4
 for the value of
b
. In particular,
fro
might observe the value
1
 for
a
 and
4
 for
b
. Thus, even though
to
 does an
assign
to
a
 and then an
assign
 to
b
, the
write
 actions to main memory may be observed
by another thread to occur as if in the opposite order.
414






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved