progress with futures

This commit is contained in:
Araq
2014-05-23 08:57:16 +02:00
parent 417b9f5a1d
commit d2dbcf2fa4
8 changed files with 68 additions and 36 deletions

View File

@@ -0,0 +1,17 @@
discard """
output: '''foobarfoobarbazbearbazbear'''
cmd: "nimrod $target --threads:on $options $file"
"""
import threadpool
proc computeSomething(a, b: string): string = a & b & a & b
proc main =
let fvA = spawn computeSomething("foo", "bar")
let fvB = spawn computeSomething("baz", "bear")
echo(^fvA, ^fvB)
main()
sync()

View File

@@ -0,0 +1,31 @@
discard """
output: '''4
8'''
cmd: "nimrod $target --threads:on $options $file"
"""
import threadpool
var
x, y = 0
proc p1 =
for i in 0 .. 10_000:
discard
atomicInc x
proc p2 =
for i in 0 .. 10_000:
discard
atomicInc y, 2
for i in 0.. 3:
spawn(p1())
spawn(p2())
sync()
echo x
echo y

View File

@@ -0,0 +1,9 @@
discard """
line: 7
errormsg: "'spawn' takes a call expression"
cmd: "nimrod $target --threads:on $options $file"
"""
import threadpool
spawn(1)