ClojureCLR

ensure improperly locking ref

Details

  • Type: Defect Defect
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Completed
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

For example:

Clojure 1.6.0-beta1
user=> (def r (ref 0))
#'user/r
user=> (dosync (ensure r))
SynchronizationLockException The read lock is being released without being held.  System.Threading.ReaderWriterLockSlim.
ExitReadLock (:0)

I'm fairly certain the call to Lock(r) in LockingTransaction.DoEnsure is incorrect. I believe it should be r.EnterReadLock()

Activity

Hide
Greg Chapman added a comment -

Also, it seems that Refs' locks have to support recursion (LockRecursionPolicy.SupportsRecursion). An ensured ref has its readlock held; any attempt to deref it (in the same transaction) will attempt to reobtain the readlock (in Ref.currentVal().

Show
Greg Chapman added a comment - Also, it seems that Refs' locks have to support recursion (LockRecursionPolicy.SupportsRecursion). An ensured ref has its readlock held; any attempt to deref it (in the same transaction) will attempt to reobtain the readlock (in Ref.currentVal().
Hide
David Miller added a comment -

It is correct that the call to Lock(r) in LockingTransaction.DoEnsure should be r.EnterReadLock()instead.
Dates back to a change in the JVM version in 2009. https://github.com/clojure/clojure/commit/961743446562b6fa7be25f96de02aacd626169da
I missed the change in call when I was editing.

This reveals the need for LockRecursionPolicy.SupportsRecursion.

Show
David Miller added a comment - It is correct that the call to Lock(r) in LockingTransaction.DoEnsure should be r.EnterReadLock()instead. Dates back to a change in the JVM version in 2009. https://github.com/clojure/clojure/commit/961743446562b6fa7be25f96de02aacd626169da I missed the change in call when I was editing. This reveals the need for LockRecursionPolicy.SupportsRecursion.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: