tmissing_deepcopy.nim 786 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. discard """
  2. matrix: "--mm:refc"
  3. ccodeCheck: "@'genericDeepCopy(' .*"
  4. action: compile
  5. """
  6. # bug #2286
  7. import threadPool
  8. type
  9. Person = ref object
  10. name: string
  11. friend: Person
  12. var
  13. people: seq[Person] = @[]
  14. proc newPerson(name:string): Person =
  15. result.new()
  16. result.name = name
  17. proc greet(p:Person) =
  18. p.friend.name &= "-MUT" # this line crashes the program
  19. echo "Person {",
  20. " name:", p.name, "(", cast[int](addr p.name),"),",
  21. " friend:", p.friend.name, "(", cast[int](addr p.friend.name),") }"
  22. proc setup =
  23. for i in 0 ..< 10:
  24. people.add newPerson("Person" & $(i + 1))
  25. for i in 0 ..< 10:
  26. people[i].friend = people[9-i]
  27. proc update =
  28. parallel:
  29. for i in 0 .. people.high:
  30. spawn people[i].greet()
  31. when true:
  32. setup()
  33. update()