tdisjoint_slice1.nim 879 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. discard """
  2. matrix: "--mm:refc"
  3. outputsub: "EVEN 28"
  4. """
  5. import threadpool, locks
  6. block one:
  7. proc odd(a: int) = echo "ODD ", a
  8. proc even(a: int) = echo "EVEN ", a
  9. proc main() =
  10. var a: array[0..30, int]
  11. for i in low(a)..high(a): a[i] = i
  12. parallel:
  13. var i = 0
  14. while i <= 29:
  15. spawn even(a[i])
  16. spawn odd(a[i+1])
  17. inc i, 2
  18. # is correct here
  19. main()
  20. block two:
  21. var echoLock: Lock
  22. initLock echoLock
  23. proc f(a: openArray[int]) =
  24. for x in a:
  25. withLock echoLock:
  26. echo x
  27. proc f(a: int) =
  28. withLock echoLock:
  29. echo a
  30. proc main() =
  31. var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9]
  32. parallel:
  33. spawn f(a[0..2])
  34. #spawn f(a[16..30])
  35. var i = 3
  36. while i <= 8:
  37. spawn f(a[i])
  38. spawn f(a[i+1])
  39. inc i, 2
  40. # is correct here
  41. main()