Ns loop ctl
Jump to navigation
Jump to search
<manpage>ns_loop_ctl</manpage>
NAME
- ns_loop_ctl - Replacements for standard Tcl loop commands which enable monitoring and control (new in AOLserver 4.5) (this command was briefly called ns_lctl in some builds)
SYNOPSIS
- ns_loop_ctl option ?arg?
DESCRIPTION
- The ns_for, ns_foreach, and ns_while commands are replacements for corresponding Tcl commands with the additional capability of monitoring and control through the ns_loop_ctl command from another thread. You can either use these commands explicitly or use ns_loop_ctl install to replace the specified command with one that can be monitored and controlled.
- ns_for start test next body
- See the Tcl for man page for usage.
- ns_foreach varlist1 list1 ?varlist2 list2 ...? body
- See the Tcl foreach man page for usage.
- ns_while test body
- See the Tcl while man page for usage.
- ns_loop_ctl cancel id
- Mark the given loop to cancel at the next iteration, resulting in the loop returning with TCL_ERROR. Returns 1 if the loop was successfully marked to be cancelled, 0 otherwise (i.e. loop is no longer running or there was no such loop id to begin with). The error message thrown inside the loop will be "loop canceled". Loops can also be cancelled using the ns_ictl cancel command whose error message is "async cancel".
- ns_loop_ctl eval id script
- Evaluates the provided script inside the loop. This command waits 2 seconds for the target thread to yield control before throwing an error and works best if the loop is first paused. You are able to both read and set any local variables inside the loop to either affect the execution (i.e. set a vwait variable) or introspect the current state of execution for debugging purposes. Note that if the provided script throws an error, this error is caught and its message returned as a string.
- ns_loop_ctl info id
- Returns a 6-element list of information about the loop: {loopId threadId loopEnterTime spins status commandAndArgs}, where loopEnterTime is the timestamp in ns_time get format when the loop was first entered, status is one of "running, paused or canceled" and commandAndArgs is the full command call of the loop (i.e. {while {1} {ns_sleep 1}}). If ns_while was explicitly used, it will say ns_while, not while.
- ns_loop_ctl install for | foreach | while
- Replaces the specified command with the monitored/controlled version for the life of the current interpreter (persists thread allocations).
- ns_loop_ctl list
- Returns a list of current loop ids in this virtual server.
- ns_loop_ctl pause id
- Mark the given loop to pause at the next iteration. Returns 1 if successfully marked, 0 otherwise. Pausing an already paused loop also returns 1.
- ns_loop_ctl resume id
- Mark the given loop to resume at the next iteration. Returns 1 if successfully marked, 0 otherwise. Resuming an already running loop also returns 1.
SEE ALSO