sidnt / zionotes

⸮ 🔴zio notes | zio nursery 🔵?
0 stars 0 forks source link

STM #2

Open sidnt opened 4 years ago

sidnt commented 4 years ago

An effect that makes transactional changes only. Nothing in between.

Scenario: There are some places in memory that need to be touched transactionally, via a transaction. And these places are subject to mutation outside my (transaction's) control as well. So a transaction can be made to retry its changes, if some parameter upstream has changed.

Computation may take time, and a transaction executes with its copy of the data, while watching those memory addresses where it got the data from, for mutations on those locations. The computation takes time. Maybe it is smart about canceling its transaction-execution, because maybe it detects midway that some source memory location has been modified, so i needn't complete the current computation because anyway i'll have to discard it if i do.

Let's say execution completes, because the input parameter memory locations haven't been modified in the meanwhile, and we have new results which are not stale, which are fresh, latest and relevant.

[~] What do we do with these fresh results? These results we would like to commit transactionally back into the memory. Do we modify the memory in one sweep?

curious #demo

Can we push STM into overdrive? Say by manipulating the memory it looks-over too fast, such that the transaction goes into a retry-loop and never actually completing.

sidnt commented 4 years ago

Software Transactional Memory is a technique which allows composition of arbitrary atomic operations.

sidnt commented 4 years ago

STM[E, A] represents an effect that can be performed transactionally, resulting in a failure E or a value A.

Does an effect that can be performed transactionally mean that the transaction's execution won't be interrupted in between? Because those are exactly the same semantics for critical sections in Brackets.

We have TRef[A], ie, a Transactional Reference. A reference that can be modified as a part of a Transaction. (ie, STM[E,A])