I found a great post explaining the re-entrancy problem but I was curious to know the various ways in which a function can be interrupted in a single-threaded environment.
final class Radiator {
private(set) var modelName: String
private(set) var serialNumber: Double
init(modelName: String, serialNumber: Double) {
self.modelName = modelName
self.serialNumber = serialNumber
}
func update(modelName: String, serialNumber: Double) {
self.modelName = modelName
self.serialNumber = serialNumber
}
}
If we created an instance of the above in memory with some initial values and then we called the update function a little later on, how would the above update function be interrupted mid execution in such a way so that the model name received a new value but the serial number did not?
Another example might be a function that opens a file, manipulates a file and then closes the file. An interruption might fail to close the file. How would that come about in a single threaded environment?