Информация об изменениях

Сообщение No concurrency safe от 12.03.2019 9:43

Изменено 12.03.2019 9:45 igor-booch

Re[2]: No concurrency safe
A>The solution is no concurrency safe — transaction is not atomic
A> me — there is no explicit requirement and actually basic
A>transaction (add) is atomic. There is no race conditions. Atomicity of
A>_transfer_ is required if we don't want to loose data — but here there
A>is no such problem since we don;t store anything between sessions.

А если:

    override fun transfer(from: String, to: String, amount: BigDecimal) {

        val amt = amount.abs()

        add(from, amt.negate())


// Здесь кто-то запросит list, и получит ответ ???!!!!

        try {
            add(to, amt)
        }
        catch (e: Exception) {
            add(from, amt) //unlikely we will have overflow here
            throw e
        }
}


получит противоречивые данные.
Так что не concurrency safe.
No concurrency safe
A>The solution is no concurrency safe — transaction is not atomic
A> me — there is no explicit requirement and actually basic
A>transaction (add) is atomic. There is no race conditions. Atomicity of
A>_transfer_ is required if we don't want to loose data — but here there
A>is no such problem since we don;t store anything between sessions.

А если:

    override fun transfer(from: String, to: String, amount: BigDecimal) {

        val amt = amount.abs()

        add(from, amt.negate())


// Здесь кто-то запросит list, и получит ответ ???!!!!

        try {
            add(to, amt)
        }
        catch (e: Exception) {
            add(from, amt) //unlikely we will have overflow here
            throw e
        }
}


получит противоречивые данные.
Так что не concurrency safe.