dcsimg
state of variable accessed by thread
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mandar_Pohnerkar
Posted On:   Saturday, April 20, 2002 12:05 AM

Suppose If we have variable ' I ' in run method, If I can
create one or more thread each thread will occupy a separate copy or
same variable will be shared ?
.

Re: state of variable accessed by thread

Posted By:   Luigi_Viggiano  
Posted On:   Saturday, April 20, 2002 01:09 AM

If the variable is declared inside the method, each invokation of the metod will have a separate instance,then the variable is thread safe.

If the variable is declared as member instance and many threads access the same object of that class, the variable should be accessed with synchronization.

If the variable is declared as static member instance and many threads access different instances of the class, the variable is again shared between threads, and needs to be synchronized.
About | Sitemap | Contact