#async #transaction #stm #memory #software #thread

async-stm

Asynchronous Software Transactional Memory

6 releases (3 breaking)

0.4.0 Aug 23, 2023
0.3.0 Aug 21, 2023
0.2.0 Feb 10, 2023
0.1.2 Apr 15, 2022
0.1.1 Mar 25, 2022

#139 in Concurrency

Download history 72/week @ 2023-11-20 117/week @ 2023-11-27 231/week @ 2023-12-04 43/week @ 2023-12-11 280/week @ 2023-12-18 18/week @ 2023-12-25 43/week @ 2024-01-01 463/week @ 2024-01-08 680/week @ 2024-01-15 803/week @ 2024-01-22 346/week @ 2024-01-29 521/week @ 2024-02-05 1012/week @ 2024-02-12 825/week @ 2024-02-19 834/week @ 2024-02-26 514/week @ 2024-03-04

3,275 downloads per month

MIT license

59KB
1.5K SLoC

STM

async-stm is an implementation of Software Transactional Memory. It was originally inspired by rust-stm, but does things sligly differently, in a more traditional fashion.

It was also extended in the following ways:

  • Made atomically asynchronous, so STM operations can be used with tokio without blocking a full thread.
  • Added the ability to abort a transaction with an error, which the caller has to handle.
  • The transaction is passed around in a thread-local variable, for a simplified TVar API.
  • Reading a TVar returns an Arc, so cloning can be delayed until we have to modify the result.
  • Added the option to pass in an auxiliary transaction that gets committed or rolled back together with the STM transaction, and can also cause a retry if it detects some conflict of its own. This is a potential way to have a hybrid persistent STM solution.
  • Added some optional queue implementations based on Simon Marlow's book, Parallel and Concurrent Programming in Haskell.

Please look at the tests for example usage.

Prerequisites

Install the following to be be able to build the project:

curl https://sh.rustup.rs -sSf | sh
rustup toolchain install nightly
rustup default stable
rustup update

Benchmarks

There are benchmarks included to help compare the tradeoffs between the different queue implementations.

cargo +nightly bench "bench" --all-features

See more

License

This project is licensed under the MIT license.

Dependencies

~2.4–9.5MB
~57K SLoC