Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var
- thr: array[0..3, system.TThread[tuple[id: int, incoming: ptr TChannel[int], outgoing: ptr TChannel[float]]]]
- job: TChannel[int]
- result: TChannel[float]
- proc threadFunc(channels: tuple[id: int, incoming: ptr TChannel[int], outgoing: ptr TChannel[float]]) {.thread.} =
- while true:
- var i = channels.incoming[].recv()
- echo("got i: ", i, " in thread: ", channels.id)
- var o: float
- o = i.float *0.5
- channels.outgoing[].send(o)
- open job
- open result
- for i in 0..high(thr):
- createThread(thr[i], threadFunc, (i, job.addr, result.addr))
- while true:
- job.send(3)
- joinThreads(thr)
Advertisement
Add Comment
Please, Sign In to add comment