Here is my minimal example: <https://play.nim-lang.org/#ix=4g1k>

(This does not actually run in the playground because it needs devel)

This example creates two threads, a ref object is created in one thread and 
sent to the other over a channel. (For now, ignore the fact there is no locking 
or memory barrier in place protecting the object itself).

This example works fine. The output looks like this:
    
    
    send a thing, @t=140031723291264 @t.val=140031728230496 t=42
    recv a thing, @t=140031725388432 @t.val=140031728230496 t=42
    
    
    Run

This shows that the ref object itself is copied by the channel, as the sender 
and receiver have their `t` on a different address. The object the ref points 
to is properly moved though, as it has the same address (`@t.val)`

This works because the created object `t` in `txProc()` has only one reference, 
so `channel.send()` will properly move the object because RC == 1 and `send` 
explicitly sinks its argument.

Uncommenting line 13 will cause problems though: there will be more then one 
reference to the same object, so after the `send()`, both threads will have a 
reference to the same object. Because the RC itself is not locked or atomic, 
this will cause UB or worse.

Reply via email to