Skip to content

Instantly share code, notes, and snippets.

@garrettwilkin
Created June 7, 2012 15:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save garrettwilkin/2889315 to your computer and use it in GitHub Desktop.
Save garrettwilkin/2889315 to your computer and use it in GitHub Desktop.
Attempting Non-blocking IO with TCL
#Non-blocking channel
set nb "data.txt"
set data [open $nb r]
fconfigure $data -blocking 0
puts "$nb [fconfigure $data]"
#Blocking channel
set bl "data2.txt"
set data2 [open $bl r]
puts "$bl [fconfigure $data2]"
#Stdout non-blocking... does this really work?
puts "stdout [fconfigure stdout]"
fconfigure stdout -blocking 0
puts "stdout [fconfigure stdout]"
#Time Check.
set then [clock clicks ]
set e [expr [clock clicks ] - $then]
puts "$then $e"
puts "Reading Non-blocking channel $nb"
set d [read $data [file size $nb]]
#Time Check.
set now [clock clicks ]
set e [expr $now - $then]
puts "$now $e"
puts "Reading Blocking channel $bl"
set d2 [read $data [file size $bl]]
#Time Check.
set now [clock clicks ]
set e [expr $now - $then]
puts "$now $e"
puts "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment