tsharedlist.nim 772 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. discard """
  2. matrix: "--threads:on"
  3. """
  4. import std/sharedlist
  5. block:
  6. var
  7. list: SharedList[int]
  8. count: int
  9. init(list)
  10. for i in 1 .. 250:
  11. list.add i
  12. for i in list:
  13. inc count
  14. doAssert count == 250
  15. deinitSharedList(list)
  16. block: # bug #17696
  17. var keysList = SharedList[string]()
  18. init(keysList)
  19. keysList.add("a")
  20. keysList.add("b")
  21. keysList.add("c")
  22. keysList.add("d")
  23. keysList.add("e")
  24. keysList.add("f")
  25. # Remove element "b" and "d" from the list.
  26. keysList.iterAndMutate(proc (key: string): bool =
  27. if key == "b" or key == "d": # remove only "b" and "d"
  28. return true
  29. return false
  30. )
  31. var results: seq[string]
  32. for key in keysList.items:
  33. results.add key
  34. doAssert results == @["a", "f", "c", "e"]