THREADS AND LOCKS
Terminology and Framework
17.1
In the absence of explicit synchronization, a Java implementation is free to
update the main memory in an order that may be surprising. Therefore the
programmer who prefers to avoid surprises should use explicit synchroniza 
tion.
17.1   Terminology and Framework
A
variable
 is any location within a Java program that may be stored into. This
includes not only class variables and instance variables but also components of
arrays. Variables are kept in a
main memory
 that is shared by all threads. Because
it is impossible for one thread to access parameters or local variables of another
thread, it doesn't matter whether parameters and local variables are thought of as
residing in the shared main memory or in the working memory of the thread that
owns them.
Every thread has a
working memory
 in which it keeps its own
working copy
 of
variables that it must use or assign. As the thread executes a Java program, it oper 
ates on these working copies. The main memory contains the
master copy
 of
every variable. There are rules about when a thread is permitted or required to
transfer the contents of its working copy of a variable into the master copy or vice
versa
The main memory also contains
locks
; there is one lock associated with each
object. Threads may compete to acquire a lock.
For the purposes of this chapter, the verbs
use
,
assign
,
load
,
store
,
lock
, and
unlock
 name
actions
 that a thread can perform. The verbs
read
,
write
,
lock
, and
unlock
 name actions that the main memory subsystem can perform. Each of these
actions is
atomic
 (indivisible).
A
use
 or
assign
 action is a tightly coupled interaction between a thread's exe 
cution engine and the thread's working memory. A
lock
 or
unlock
 action is a
tightly coupled interaction between a thread's execution engine and the main
memory. But the transfer of data between the main memory and a thread's work 
ing memory is loosely coupled. When data is copied from the main memory to a
working memory, two actions must occur: a
read
 action performed by the main
memory followed some time later by a corresponding
load
 action performed by
the working memory. When data is copied from a working memory to the main
memory, two actions must occur: a
store
 action performed by the working mem 
ory followed some time later by a corresponding
write
 action performed by the
main memory. There may be some transit time between main memory and a
working memory, and the transit time may be different for each transaction; thus
actions initiated by a thread on different variables may viewed by another thread
as occurring in a different order. For each variable, however, the actions in main
401






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