Marthog / rust-stm

Software transactional memory
Apache License 2.0
249 stars 15 forks source link

Possible deadlock #19

Closed chosen-ox closed 1 year ago

chosen-ox commented 1 year ago

Hi, I am reviewing the source code and have a question.

https://github.com/Marthog/rust-stm/blob/91628b415ab401aa3d67f0c9e8a1f2e686ce1a6b/stm-core/src/transaction/mod.rs#L323-L333

During commit process, the transaction grabs all write locks and then writes values together. I wonder if there is a possible deadlock during this process. For example, there are two Tvar var_A and var_B. transaction_1 grabs var A write lock an transaction_2 grabs var_B write lock. Then they both try to grab another write lock which causes a deadlock.

If I was wrong, feel free to correct me.

chosen-ox commented 1 year ago

It won't cause deadlock. Because btreemap sorted by key. My bad.