Posted to tcl by mjanssen at Sat Apr 22 20:11:04 GMT 2017view raw

  1. puts "[thread::id] All workers done, exiting"
  2. set ::workers_done 1
  3. }
  4. }
  5.  
  6. proc start_worker {main} {
  7. set id [thread::create {
  8. proc start tid {
  9. while 1 {
  10. puts "[thread::id]: Asking for work"
  11. set work [thread::send $tid getwork]
  12. if {$work ne {}} {
  13. puts "[thread::id]: Doing work $work"
  14. after 1000
  15. } else {
  16. puts "[thread::id]: No more work"
  17. thread::send $tid [list remove_worker [thread::id]]
  18. thread::exit
  19. }
  20. }
  21. }
  22. vwait forever
  23. }]
  24. thread::send -async $id [list start $main]
  25. lappend ::workers $id
  26. }
  27. # start 2 workers
  28. time [list start_worker [thread::id]] 2
  29.  
  30. vwait workers_done
  31.  
  32.