tdeepcopy2.nim 639 B

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