#!/usr/bin/tclsh

package require Thread

proc connected {fd} {
    close $fd
    exit
}

# True: use main thread, False: use helper thread
if {false} {
    set sock [socket -async dns.google 53]
} else {
    set tid [thread::create]
    set sock [thread::send $tid {
	set fd [socket -async dns.google 53]
	thread::detach $fd
	set fd
    }]
    thread::attach $sock
}

fileevent $sock writable [list connected $sock]
vwait forever
