This commit is contained in:
Araq
2011-12-04 20:21:38 +01:00
parent 3c4260f504
commit 24e1d22ec9
2 changed files with 11 additions and 11 deletions

View File

@@ -129,24 +129,24 @@ template setupTask =
template schedule =
# extremely simple scheduler: We always try the first thread first, so that
# it remains 'hot' ;-). Round-robin hurts for keeping threads hot.
for i in 0..high(a.actors):
if a.actors[i].i.ready:
a.actors[i].i.send(t)
for i in 0..high(p.actors):
if p.actors[i].i.ready:
p.actors[i].i.send(t)
return
# no thread ready :-( --> send message to the thread which has the least
# messages pending:
var minIdx = 0
var minVal = high(int)
for i in 0..high(a.actors):
var curr = a.actors[i].i.peek
for i in 0..high(p.actors):
var curr = p.actors[i].i.peek
if curr == 0:
# ok, is ready now:
a.actors[i].i.send(t)
p.actors[i].i.send(t)
return
if curr < minVal:
minVal = curr
minIdx = i
a.actors[minIdx].i.send(t)
p.actors[minIdx].i.send(t)
proc spawn*[TIn, TOut](p: var TActorPool[TIn, TOut], input: TIn,
action: proc (input: TIn): TOut {.thread.}

View File

@@ -5,9 +5,9 @@ discard """
import actors
var
a: TActorPool[int, void]
createActorPool(a)
pool: TActorPool[int, void]
createActorPool(pool)
for i in 0 .. < 300:
a.spawn(i, proc (x: int) {.thread.} = echo x)
a.join()
pool.spawn(i, proc (x: int) {.thread.} = echo x)
pool.join()