tdisjoint_slice2.nim 505 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. discard """
  2. output: '''0
  3. 1
  4. 2
  5. 3
  6. 4
  7. 5
  8. 6
  9. 7
  10. 8'''
  11. sortoutput: true
  12. """
  13. import threadpool, locks
  14. var echoLock: Lock
  15. initLock echoLock
  16. proc f(a: openArray[int]) =
  17. for x in a:
  18. withLock echoLock:
  19. echo x
  20. proc f(a: int) =
  21. withLock echoLock:
  22. echo a
  23. proc main() =
  24. var a: array[0..9, int] = [0,1,2,3,4,5,6,7,8,9]
  25. parallel:
  26. spawn f(a[0..2])
  27. #spawn f(a[16..30])
  28. var i = 3
  29. while i <= 8:
  30. spawn f(a[i])
  31. spawn f(a[i+1])
  32. inc i, 2
  33. # is correct here
  34. main()