treadafterwrite.nim 643 B

1234567891011121314151617181920212223242526272829303132
  1. discard """
  2. errormsg: "'foo' not disjoint from 'foo'"
  3. line: 23
  4. disabled: "true"
  5. """
  6. # bug #1597
  7. import strutils, math, threadpool
  8. type
  9. BoxedFloat = object
  10. value: float
  11. proc term(k: float): ptr BoxedFloat =
  12. var temp = 4 * math.pow(-1, k) / (2*k + 1)
  13. result = cast[ptr BoxedFloat](allocShared(sizeof(BoxedFloat)))
  14. result.value = temp
  15. proc pi(n: int): float =
  16. var ch = newSeq[ptr BoxedFloat](n+1)
  17. parallel:
  18. for k in 0..ch.high:
  19. let foo = (spawn term(float(k)))
  20. assert foo != nil
  21. for k in 0..ch.high:
  22. var temp = ch[k][].value
  23. result += temp
  24. deallocShared(ch[k])
  25. echo formatFloat(pi(5000))