Synchronize the code

Report a typo

Here's a class named SimpleClass. It has two fields of different types and a method to initialize these fields.

class SimpleClass {

    var strField: String = ""
    var numField: Int = 0

    fun initFields(str: String, number: Int) {
        strField = str    // 1
        numField = number // 2
    }
}

Multiple threads are trying to invoke the initFields method of the class. You need to synchronize this code so that a thread would not be able to set new values until another thread has set both of them (in a way an atomic operation does).

How can one do it? Select all correct cases.

Select one or more options from the list
___

Create a free account to access the full topic