T
T
TheStrangeWind2017-02-08 22:45:12
Java
TheStrangeWind, 2017-02-08 22:45:12

Is it possible to use a volatile variable for summation?

Let's say there are several threads, they add some values ​​to a volatile variable, and output the values ​​of this variable after real-time summation.
Is it possible to do so? What problems will arise?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
GavriKos, 2017-02-08
@TheStrangeWind

Non-atomic operations on volatile variables are not thread-safe. Read more here - https://habrahabr.ru/post/108016/ - point 4

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question