nim-works / loony

A high throughput MPMC lock-free queue based on a paper by Giersch, Nolte et al implemented in pure Nim.
https://nim-works.github.io/loony/
MIT License
65 stars 4 forks source link

SIGSEGV on q.isEmpty #27

Closed Asc2011 closed 8 months ago

Asc2011 commented 2 years ago

Hi,

i see SIGSEGV on calls to queue.isEmpty. The queue is initialized using newLoonyQueue. It has not received any items yet. I tried if- and while - makes no difference. I tried std/atomics and threading/atomics. It feels a bit like a timing/init-problem. Though i never managed to make it work reliably. Goes like this - the whole app runs thru and finishes. Then on the next run it breaks early. On the following start i might run and finish or break in-between. I use the main-thread to fill the queue and one separate thread to read and process the items from the queue ? A queue-items contains a seq[int], int, string, so nothing special here.

Im on Nim 1.6.6 / macOS

this is my thread-proc ::

proc warden[K, V]( map: Map[K, V] ) {.thread, nimcall.} =

  echo "maintanance:: started"

  while true:

    while map.workQ.isEmpty:
      sleep 500
      continue

    var elem = map.workQ.pop
    #if elem.isNil: break
    echo &"ward :: ", elem.task, " :: ", elem.parent, " - ",elem.slot

    if elem.slot == -1:
      echo "\nmaintanance:: shuts down..\n"
      return

Traceback for :

nim r -d:b32 --gc:arc --threads:on -d:useMalloc -d:debug -d:nimOldCaseObjects Mapi.nim

/Users/asc/sw/nim/ctrie/champ/Mapi.nim(30) warden
/Users/asc/.nimble/pkgs/loony-0.1.12/loony.nim(68) isEmpty
/Users/asc/.choosenim/toolchains/nim-1.6.6/lib/pure/concurrency/atomics.nim(336) load
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Error: execution of an external program failed: '/Users/asc/.cache/nim/Mapi_d/Mapi_558E24AF8FBA3F576C55E835091AA4F6A61AFFB3 '
disruptek commented 2 years ago

If you can provide a complete example, I don't mind taking a look. Have you tried running it in a debugger to see what's happening? I don't have mainline nim 1.6.6; do you have 1.6.5, by any chance?