ClojureCLR

compare-and-set! broken

Details

  • Type: Defect Defect
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None
  • Environment:
    Clojure CLR 1.5.0 Release 4.0, Windows 7 (64-bit), .NET 4.0.30319.18444

Description

Here's a simple sample of using compare-and-swap! on jvm clojure:

user=> (def a (atom 0))
#'user/a
user=> (compare-and-set! a 0 1)
true
user=> @a
1
user=> clojure-version
{:major 1, :minor 5, :incremental 1, :qualifier nil}

Here's what happens on clojure-clr:

user=> (def a (atom 0))
#'user/a
user=> (compare-and-set! a 0 1)
false
user=> @a
0
user=> clojure-version
{:major 1, :minor 5, :incremental 0, :qualifier ""}

The only value I could get it to work correctly with was nil.

Activity

Hide
David Miller added a comment -

The observed behavior is because the JVM caches small boxed integers and the CLR does not.

compare-and-set! reveals a very low-level implementation detail. Trying to match the behavior exactly is not worth the effort. Prefer swap! to compare-and-set! if it matters.

Show
David Miller added a comment - The observed behavior is because the JVM caches small boxed integers and the CLR does not. compare-and-set! reveals a very low-level implementation detail. Trying to match the behavior exactly is not worth the effort. Prefer swap! to compare-and-set! if it matters.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: