tmissing_deepcopy.nim 765 B

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