fixes 70
This commit is contained in:
parent
3c4260f504
commit
24e1d22ec9
2 changed files with 11 additions and 11 deletions
|
|
@ -129,24 +129,24 @@ template setupTask =
|
||||||
template schedule =
|
template schedule =
|
||||||
# extremely simple scheduler: We always try the first thread first, so that
|
# extremely simple scheduler: We always try the first thread first, so that
|
||||||
# it remains 'hot' ;-). Round-robin hurts for keeping threads hot.
|
# it remains 'hot' ;-). Round-robin hurts for keeping threads hot.
|
||||||
for i in 0..high(a.actors):
|
for i in 0..high(p.actors):
|
||||||
if a.actors[i].i.ready:
|
if p.actors[i].i.ready:
|
||||||
a.actors[i].i.send(t)
|
p.actors[i].i.send(t)
|
||||||
return
|
return
|
||||||
# no thread ready :-( --> send message to the thread which has the least
|
# no thread ready :-( --> send message to the thread which has the least
|
||||||
# messages pending:
|
# messages pending:
|
||||||
var minIdx = 0
|
var minIdx = 0
|
||||||
var minVal = high(int)
|
var minVal = high(int)
|
||||||
for i in 0..high(a.actors):
|
for i in 0..high(p.actors):
|
||||||
var curr = a.actors[i].i.peek
|
var curr = p.actors[i].i.peek
|
||||||
if curr == 0:
|
if curr == 0:
|
||||||
# ok, is ready now:
|
# ok, is ready now:
|
||||||
a.actors[i].i.send(t)
|
p.actors[i].i.send(t)
|
||||||
return
|
return
|
||||||
if curr < minVal:
|
if curr < minVal:
|
||||||
minVal = curr
|
minVal = curr
|
||||||
minIdx = i
|
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,
|
proc spawn*[TIn, TOut](p: var TActorPool[TIn, TOut], input: TIn,
|
||||||
action: proc (input: TIn): TOut {.thread.}
|
action: proc (input: TIn): TOut {.thread.}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,9 @@ discard """
|
||||||
import actors
|
import actors
|
||||||
|
|
||||||
var
|
var
|
||||||
a: TActorPool[int, void]
|
pool: TActorPool[int, void]
|
||||||
createActorPool(a)
|
createActorPool(pool)
|
||||||
for i in 0 .. < 300:
|
for i in 0 .. < 300:
|
||||||
a.spawn(i, proc (x: int) {.thread.} = echo x)
|
pool.spawn(i, proc (x: int) {.thread.} = echo x)
|
||||||
a.join()
|
pool.join()
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue