Posted to tcl by karll at Wed Mar 25 21:15:16 GMT 2015view raw

  1. #
  2. # tcl thread eventmark bug demo
  3. #
  4. # creates a producer thread and uses the main thread as a consumer thread
  5. #
  6. # the consumer thread sends to the producer thread to invoke blast,
  7. # a proc that continuously generates async events to the consumer thread
  8. #
  9. # the consumer thread is configured using thread::configure -eventmark
  10. # to limit the number of asynchronously posted scripts to the consumer's
  11. # thread event loop
  12. #
  13. # the bug is that once the eventmark limit is reached, no further events
  14. # are sent
  15. #
  16. # apparently the consumer consuming events does not decrease the number
  17. # of pending events that the eventmark is looking at, or the act of
  18. # performing pending events does not wake up the producer
  19. #
  20. # if you comment out the eventmark config, it works as expected
  21. #
  22. # also if you use thread::wait on the consumer thread instead of vwait
  23. # it works
  24. #
  25.  
  26. package require Thread
  27.  
  28. set consumerThread [thread::id]
  29.  
  30. thread::configure $consumerThread -eventmark 20
  31.  
  32. set producerThread [thread::create {
  33.  
  34. proc blast {thread} {
  35. while true {
  36. thread::send -async $thread hiya
  37. }
  38. }
  39.  
  40. thread::wait
  41. }]
  42.  
  43. proc hiya {} {
  44. puts "hiya [incr ::hiyaCount]"
  45. }
  46.  
  47. thread::send -async $producerThread [list blast $consumerThread]
  48.  
  49. vwait die
  50. #thread::wait
  51.