Guest User

Untitled

a guest
Nov 22nd, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. var
  2. thr: array[0..3, system.TThread[tuple[id: int, incoming: TChannel[int], outgoing: TChannel[float]]]]
  3. job: TChannel[int]
  4. result: TChannel[float]
  5.  
  6. proc threadFunc(channels: tuple[id: int, incoming: TChannel[int], outgoing: TChannel[float]]) {.thread.} =
  7. while true:
  8. var i : int
  9. channels.incoming.recv()
  10. echo("got i: ", i, " in thread: ", channel.id)
  11. var o: float
  12. o = i*0.5
  13. channels.outgoing.send(o)
  14.  
  15. for i in 0..high(thr):
  16. createThread(thr[i], threadFunc, (i, job, result))
  17. while true:
  18. job.send(3)
  19. joinThreads(thr)
Advertisement
Add Comment
Please, Sign In to add comment