Guest User

Untitled

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