ns_thread(3aolserver) | AOLserver Built-In Commands | ns_thread(3aolserver) |
NAME¶
ns_thread - commandsSYNOPSIS¶
ns_thread begin script ns_thread begindetached script ns_thread get ns_thread getid ns_thread wait tid ns_thread yieldDESCRIPTION¶
ns_thread begin:begins a new thread which evaluates the
specified script and then exits. It returns a thread ID that must eventually
be passed to ns_thread wait. (Failing to call ns_thread wait will eventually
result in no new threads being created.)
begins a detached thread that doesn't have to
be (and can't be) waited for.
gets the thread ID of the current thread. The
result is a thread ID that can be passed to ns_thread wait and may look
something like "tid532".
gets the thread integer number for the current
thread. The result is a small integer used for identifying threads is a
human-readable way, such as "1" or "1120", for
example.
waits for the specified thread to exit. The
tid argument is a thread ID returned by ns_thread begin or ns_thread
get.
causes the current thread to yield.
EXAMPLES¶
global pages
# new thread will start here - first connect to host
set host [format "www%2d.foo.com" $i]
set fds [ns_sockopen $host 80
set r [lindex $fds 0]
set w [lindex $fds 1]
# next, send request
puts $w "GET /index.htm HTTP/1.0r0r"
flush $w
# then read page
set pages($i) [read $r]
# and close sockets
close $w
close $r
# thread goes away here and other threads waiting
# on ns_thread wait will wakeup }
set tids($i) [ns_thread begin "getpage $i"] }
ns_thread wait $tids($i)
# output page
... process the page in $pages($i) put there by other thread ... }
SEE ALSO¶
KEYWORDS¶
threads4.0 | AOLserver |