Posted to tcl by Whiskey at Thu Mar 21 13:53:14 GMT 2013view pretty
# Set packages package require Thread # Create ThreadStarter proc Start {one two three} { # Set MasterID set mid [thread::id] # Set shared variables tsv::set thread mid $mid # Create thread set tid [thread::create { # Set packages package require struct::queue # Create thread proc proc Start-Thread {one two three} { # Set variables set mid "[tsv::set thread mid]" set tid "[thread::id]" # Send massage thread::send $mid [list puts "I was here: $tid"] } # Create queue proc proc isQueue {one two three} { # Create queue set queue [struct::queue] # Put jobs in queue $queue put [list Start-Thread "$one" "$two" "$three"] # Check for jobs in queue while {[$queue size]} { eval [$queue get] } # Remove queue $queue destroy } thread::wait }] # Start thread thread::send -async $tid [list isQueue "$one" "$two" "$three"] } # Test result in loop proc loop {n} { for {set i 0} {$i < $n} {incr i} { Start "1" "2" "3" } } loop 20 after 3000 update