RosettaCodeData/Task/Synchronous-concurrency/Tcl/synchronous-concurrency.tcl
Ingy döt Net 68f8f3e56b all tasks
2013-04-11 01:07:29 -07:00

28 lines
626 B
Tcl

package require Thread
# Define the input thread
set input [thread::create {
proc readFile {filename receiver} {
set f [open $filename]
while {[gets $f line] >= 0} {
thread::send $receiver [list line $line]
}
close $f
thread::send $receiver lineCount lines
puts "got $lines lines"
}
thread::wait
}]
# Define the output thread
set output [thread::create {
set lines 0
proc line {string} {
puts $string
incr ::lines
}
proc lineCount {} {return $::lines}
thread::wait
}]
# Connect everything together and start the processing
thread::send $input [list readFile "input.txt" $output]