nim-lang / threading

New atomics, thread primitives, atomic refcounting for --gc:arc/orc.
MIT License
73 stars 12 forks source link

Does channel `send` have the correct ordering? #51

Open elcritch opened 11 months ago

elcritch commented 11 months ago

Is the ordering of the GC_runOrc and wasMoved correct?

Intuitively I'd think that it'd be wasMoved then running GC_runOrc to handle cleaning up the ORC "roots" from the current thread? I'm not sure where/when the ORC cycle "roots" added or removed.

I could also be misunderstanding the intent of running GC_runOrc at this point, which I'd like to understand as well.

proc send*[T](c: Chan[T], src: sink Isolated[T]) {.inline.} =
  ## Sends item to the channel (blocking).
  var data = src.extract
  when defined(gcOrc) and defined(nimSafeOrcSend):
    GC_runOrc()
  discard channelSend(c.d, data.unsafeAddr, sizeof(T), true)
  wasMoved(data)