There’s volatile in Java ( annotation in Kotlin) that can be used on fields. There are multiple ways to achieve this which are explained below. ![]() In order to fix this issue, we need to synchronize the work on this value. ![]() This is why the final value is not what we expect. This problem can occur in similar other ways, for example, a thread gets past the second level, but before storing it, other threads increment and save the sharedCounter value, and when the first thread jumps in for its third step, it saves an older version of the sharedCounter.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |