tdeepcopy2.nim 617 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. discard """
  2. output: '''
  3. called deepCopy for int
  4. called deepCopy for int
  5. done999 999
  6. '''
  7. """
  8. import threadpool
  9. type
  10. Bar[T] = object
  11. x: T
  12. proc `=deepCopy`[T](b: ref Bar[T]): ref Bar[T] =
  13. result.new
  14. result.x = b.x
  15. when T is int:
  16. echo "called deepCopy for int"
  17. else:
  18. echo "called deepCopy for something else"
  19. proc foo(b: ref Bar[int]): int = 999
  20. # test that the disjoint checker deals with 'a = spawn f(); g = spawn f()':
  21. proc main =
  22. var dummy: ref Bar[int]
  23. new(dummy)
  24. dummy.x = 44
  25. #parallel:
  26. let f = spawn foo(dummy)
  27. let b = spawn foo(dummy)
  28. echo "done", ^f, " ", ^b
  29. main()