tdeepcopy2.nim 625 B

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