
package require Thread

for {set i 1} {$i < 15} {incr i} {

    puts "###############Inside Test $i"
    after 5000 {set flag 1}
    set script {puts "Inside Thread"
        puts "Inside Thread"
        puts "Inside Thread"
        puts "Inside Thread"
        puts "Inside Thread"
       thread::release
    }
    set noThread 5     
    for {set n 1} {$n <= $noThread} {incr n} {
        eval set threadId$n [thread::create -joinable]       
    }
    for {set n 1} {$n <= $noThread} {incr n} { 
        if {[catch {eval thread::send -async \$threadId$n \$script} msg]} {
            error "send script failed  $msg : $::errorInfo"
        }
    }

    for {set n 1} {$n <= $noThread} {incr n} {
        eval puts "\"Before Join \$threadId$n\""
        eval thread::join \$threadId$n
        puts "Check $threadId1 exist [eval thread::exists \$threadId$n]"
    }

    puts "Waiting..................$i"
    vwait flag

}

# end of file
