|
Re: volatile long: msg#00028java.jsr.166-concurrency
Hanson Char wrote: > Thanks Joe, I did some experiment and the result is on your side. The > ++count is a read-modify-write operation, not a pure write operation. > So volatile will never work with such construct. > > Hanson Yup, volatile only makes the reads and writes atomic, not combinations of reads and writes. And ++ is definitely a read and a write (how else will it know the value to increment?). In case you're interested, here's an example execution of how you can get count to be negative: count initially 0 Thread 1 Thread 2 read count (0) read count (0) write count = 1 write count = 1 read count (1) write count = 0 read count (0) write count = -1 - Victor
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | Re: volatile long, Hanson Char |
|---|---|
| Next by Date: | RE: volatile long, David Holmes |
| Previous by Thread: | Re: volatile long, Hanson Char |
| Next by Thread: | RE: volatile long, David Holmes |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |