## Standalone reproduction of Nim 2.2.10's allocator sanitizer report. ## No logging-library imports. All accesses to the shared sequence hold a lock. import std/[atomics, locks] type AllocatorData = object lock: Lock entries: seq[int] total: int var start: Atomic[bool] proc withData(data: ptr AllocatorData, action: proc(entries: var seq[int]) {.gcsafe.}) = withLock data.lock: action(data.entries) inc data.total proc append(data: ptr AllocatorData, value: int) = data.withData(proc(entries: var seq[int]) = entries.add(value) if entries.len >= 64: entries = @[]) proc worker(data: ptr AllocatorData) {.thread.} = while not start.load(): discard for i in 0 ..< 10_000: data.append(i) proc runAllocatorRegression*() = var data: AllocatorData initLock(data.lock) defer: deinitLock(data.lock) var workers: array[4, Thread[ptr AllocatorData]] for thread in workers.mitems: createThread(thread, worker, addr data) start.store(true) joinThreads(workers) doAssert data.total == 40_000 when isMainModule: runAllocatorRegression()