logo       

volatile long: msg#00021

java.jsr.166-concurrency

Subject: volatile long

A question on the use of volatile in a concurrent environment.
Consider the example:

public class Foo {
private volatile int count;

public void run() {
count++;
// ... do some other operations
count--;
}
public int getCount() { return count; }
}

My understanding is:

1) The value returned by getCount() will never be less than zero; and
2) count will never be in a corrupted state.

Does the above 2 statements still hold if count is type long instead of int ?

Hanson


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise