Well you went unsafe by using cast[ptr History] and that's what you get when 
you modify one gc backed object from another thread, by adding foreign thread 
gc objects to it. This is happening because every thread has its own "heap" and 
his own GC. And every GC once finds a ref requires it to be either nil or 
originated from its own heap. Example: 
    
    
    type Foo = object
      next: ref Foo
    
    proc backgroundThread(f: ptr Foo) =
      f.next.new()
    
    proc mainThread() =
      var f: ref Foo
      f.new()
      spawn backgroundThread(cast[ptr Foo](f))
    
    
    Run

I haven't tested the above code if it compiles, but hopefully the idea is clear.

Reply via email to