Water 5-Concurrent Programming-ThreadContract| Parameter key | Default value | Type | | id | null | | env_or_context | null | | native_object | opt | | Parameter kind | Default value | Type | | Other unkeyed arguments | opt with ekind of string | wob | | Water Contract<class thread
id =null
env_or_context=null
native_object =opt
_part_name_key="id"
_other_unkeyed=opt=wob=ekind.string="_add_to_environment"
/> | |
Threads allow more than one sequence of instructions to be executing
simultaneously. If there are fewer physical processors than active threads,
each thread will get a time slice of the processor to run before
another thread gets a chance to run. Typically each time slice is
on the order of 10 milliseconds, but programs will often yield their time slice
early if (for example), they need to wait for disk or network access.
This makes thread-based programs ideal for I/O-bound applications, because
time spent waiting for a resource can still be used by other threads.
The operating system schedules the time slices so the programmer doesn't
have explicit control.
However, programmers do have some control over threads. A thread can:
When instances of the thread class are created, they are cached in the 'of'
field of thread in the usual way. This creates the thread but does not run it.
<thread id="myt"> <echo "myt execution with: " thread.<current/>/> </thread>
 | thread.of.myt |
Example: returns false since we haven't started this thread yet
thread.of.myt.<is_started/>
false
Starts myt and returns immediately, but in parallel, the echo code
above is called in the new thread.
thread.of.myt.<start/>
thread.of.myt thread.of.myt.<is_started/>
true Example: returns true if the thread has been started and isn't done
thread.of.myt.<is_running/>
false Example: returns true when the call to echo completes
thread.of.myt.<is_done/>
true
Water threads are implemented on top of Java threads.
You can get at the underlying Java thread from a water thread via its 'native_object' field.
thread.of.myt.native_object
© Copyright 2007 Clear Methods, Inc.