Skip to content

Segfaults in atomic-counter (regression in 9.6)

I've come across what I think are more than one distinct bugs in running atomic-counter's benchmarks. If we are able to discern them later ahead we can create a separate ticket.

The easiest to reproduce is an immediate segfault on start with 9.6.1 and HEAD which doesn't occur with other versions. Simply clone atom-counter and run cabal run bench -- -j1 with 9.1.

Note that any value passed with -j will cause the segfault. Omitting the -j flag will make the program no longer segfault.

The other is bug seems to be related to concurrency/atomic operations. I was able to somewhat reliably reproduce by running cabal bench with 9.6, and could reproduce another crash with 9.4 but less reliably.

$ cabal bench
All
  Correctness:          OK (3.49s)
    +++ OK, passed 10000 tests.
  Read/write contention with 10 iterations and 1 threads
    Counter:            OK (0.45s)
      18.1 μs ± 1.6 μs
    IORef inconsistent: OK (1.83s)
      18.1 μs ± 1.7 μs, 1.00x
    IORef atomic:       OK (1.05s)
      20.1 μs ± 1.6 μs, 1.11x
    MVar:               OK (1.00s)
      18.9 μs ± 1.3 μs, 1.04x
    TMVar:              OK (0.57s)
      22.7 μs ± 1.6 μs, 1.25x
    TVar:               OK (1.17s)
      22.6 μs ± 1.8 μs, 1.25x
    Addr:               OK (0.47s)
      17.3 μs ± 1.7 μs, 0.96x
  Read/write contention with 100 iterations and 1 threads
    Counter:            OK (0.66s)
      26.4 μs ± 1.7 μs
    IORef inconsistent: OK (0.39s)
      29.2 μs ± 2.4 μs, 1.11x
    IORef atomic:       OK (1.76s)
      39.1 μs ± 2.6 μs, 1.48x
    MVar:               OK (0.43s)
      32.6 μs ± 3.2 μs, 1.24x
    TMVar:              bench: internal error: TSO object (0x16d65ee40) entered!
    (GHC version 9.6.1 for aarch64_apple_darwin)
    Please report this as a GHC bug:  https://www.haskell.org/ghc/reportabug
Benchmark bench: ERROR
Error: cabal: Benchmarks failed for bench:bench from atomic-counter-0.1.

Architecture: aarch64 (Apple Silicon)

Edited by Rodrigo Mesquita
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information