fixes #1597
This commit is contained in:
parent
b7c8063816
commit
393be49313
3 changed files with 86 additions and 8 deletions
31
tests/parallel/treadafterwrite.nim
Normal file
31
tests/parallel/treadafterwrite.nim
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
discard """
|
||||
errormsg: "'foo' not disjoint from 'foo'"
|
||||
line: 23
|
||||
disabled: "true"
|
||||
"""
|
||||
|
||||
# bug #1597
|
||||
|
||||
import strutils, math, threadpool
|
||||
|
||||
type
|
||||
BoxedFloat = object
|
||||
value: float
|
||||
|
||||
proc term(k: float): ptr BoxedFloat =
|
||||
var temp = 4 * math.pow(-1, k) / (2*k + 1)
|
||||
result = cast[ptr BoxedFloat](allocShared(sizeof(BoxedFloat)))
|
||||
result.value = temp
|
||||
|
||||
proc pi(n: int): float =
|
||||
var ch = newSeq[ptr BoxedFloat](n+1)
|
||||
parallel:
|
||||
for k in 0..ch.high:
|
||||
let foo = (spawn term(float(k)))
|
||||
assert foo != nil
|
||||
for k in 0..ch.high:
|
||||
var temp = ch[k][].value
|
||||
result += temp
|
||||
deallocShared(ch[k])
|
||||
|
||||
echo formatFloat(pi(5000))
|
||||
31
tests/parallel/tuseafterdef.nim
Normal file
31
tests/parallel/tuseafterdef.nim
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
discard """
|
||||
errormsg: "(k)..(k) not disjoint from (k)..(k)"
|
||||
line: 23
|
||||
"""
|
||||
|
||||
# bug #1597
|
||||
|
||||
import strutils, math, threadpool
|
||||
|
||||
type
|
||||
BoxedFloat = object
|
||||
value: float
|
||||
|
||||
proc term(k: float): ptr BoxedFloat =
|
||||
var temp = 4 * math.pow(-1, k) / (2*k + 1)
|
||||
result = cast[ptr BoxedFloat](allocShared(sizeof(BoxedFloat)))
|
||||
result.value = temp
|
||||
|
||||
proc pi(n: int): float =
|
||||
var ch = newSeq[ptr BoxedFloat](n+1)
|
||||
parallel:
|
||||
for k in 0..ch.high:
|
||||
ch[k] = (spawn term(float(k)))
|
||||
assert ch[k] != nil
|
||||
for k in 0..ch.high:
|
||||
var temp = ch[k][].value
|
||||
result += temp
|
||||
deallocShared(ch[k])
|
||||
|
||||
|
||||
echo formatFloat(pi(5000))
|
||||
Loading…
Add table
Add a link
Reference in a new issue