@Volatile and atomic operations

Report a typo

Here's a list of different functions:

  • setting a specified Long value to a Long field (without @Volatile)
fun setLong(value: Long) {
    this.value = value
}
  • setting a specified Int value to an Int field (without @Volatile)
fun setInt(value: Int) {
    this.value = value
}
  • increment the Int field by n (without @Volatile)
fun incrementBy(n: Int) {
    this.field += n
}
  • setting a specified Int value to an Int field (without @Volatile) and increment the field by one
fun setAndInc(value: Int) {
    this.value = value
    this.value++
}
  • setting a specified Long value to a Long field (with @Volatile)
fun setLongVolatile(value: Long) {
    this.value = value
}

Select all the functions that represent atomic operations. It means that when a thread changes a value, other threads will not be able to access any intermediate values. They should only read the value as it was before the invocation of the function and after the function has completed its work.

Select one or more options from the list
___

Create a free account to access the full topic