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