Re: RE: Synchronization of data read by multiplethreads

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: RE: Synchronization of data read by multiplethreads

Dawid Kurzyniec
Ryan LeCompte wrote:

>
> Hello all,
>
>
>
> As a follow-on to my original question… I have another scenario where
> I’m not entirely sure if synchronization/volatile is needed. Let’s say
> we have the following:
>
>
>
> Class Test implements Runnable {
>
> Private boolean instantiated = false;
>
>
>
> Public Test() {
>
> Instantiated = true;
>
> }
>
>
>
> private boolean isInstantiated() {
>
> Return instantiated;
>
> }
>
>
>
> Public void run() {
>
> If (isInstantiated()) {
>
> // do something
>
> }
>
> }
>
> }
>
Just a question: why do you need the "instantiated" field in the first
place? Do you ever set it to false? If not, it can be made final, and
consequently, removed completely. If yes, you probably set it from
another thread, so you may need synchronization after all.

Regards,
Dawid



_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest