
Rebuilding the Demo Host Software
A-18
The new thread may print its message between the two main thread's
messages or after. The new thread also could run a loop, perhaps
sleeping occasionally by calling java.lang.Thread.sleep(<milliseconds>)
or yielding the CPU with java.lang.Thread.yield(). This is all standard for
any threading system; the difference is only the ease of thread creation.
All threads can read and write the script's global variables. For example,
the fileio thread loops while the "stopFileIoThreadFlag" global variable is
false. This variable is set to true by the main() function when it exits.
Threads whose "run" functions are defined inline—as in the "Hello world"
example above—have access to all the variables in the scope of the
function that defined them. That lets us define quick, short thread
functions without having to define separate functions and pass on piles
of variables.
The only exception to this idyllic picture comes when different threads
need to access GUI objects: "shell" and "myWidgets[]" in our case. They
cannot be accessed directly from a thread other than the main thread. For
example, this would fail:
// main thread
w["myText"].setText( "lovely" );
new java.lang.Thread( new java.lang.Runnable() {
run: function() {
// new thread
print( "Hello " + w["myText"].getText() + " world" );
}
} ).start();
Содержание TMS320DM6437
Страница 1: ...TMS320DM6437 DVDP Getting Started Guide Literature Number SPRUEV6 July 2007 ...
Страница 20: ...2 8 ...
Страница 34: ...3 14 ...
Страница 40: ...4 6 ...
Страница 63: ......
Страница 64: ...Spectrum Digital Inc 509108 0001B ...