Posted to tcl by karll at Wed Mar 25 21:15:16 GMT 2015view raw
- #
- # tcl thread eventmark bug demo
- #
- # creates a producer thread and uses the main thread as a consumer thread
- #
- # the consumer thread sends to the producer thread to invoke blast,
- # a proc that continuously generates async events to the consumer thread
- #
- # the consumer thread is configured using thread::configure -eventmark
- # to limit the number of asynchronously posted scripts to the consumer's
- # thread event loop
- #
- # the bug is that once the eventmark limit is reached, no further events
- # are sent
- #
- # apparently the consumer consuming events does not decrease the number
- # of pending events that the eventmark is looking at, or the act of
- # performing pending events does not wake up the producer
- #
- # if you comment out the eventmark config, it works as expected
- #
- # also if you use thread::wait on the consumer thread instead of vwait
- # it works
- #
- package require Thread
- set consumerThread [thread::id]
- thread::configure $consumerThread -eventmark 20
- set producerThread [thread::create {
- proc blast {thread} {
- while true {
- thread::send -async $thread hiya
- }
- }
- thread::wait
- }]
- proc hiya {} {
- puts "hiya [incr ::hiyaCount]"
- }
- thread::send -async $producerThread [list blast $consumerThread]
- vwait die
- #thread::wait