Start Policy
In the Threading package, new threads of execution are created by calling the start() member on an instance of a threaded runnable class. The start() function creates a new thread and immediately interrupts that thread in order to make any necessary adjustments to the thread’s scheduling attributes before the thread starts executing within its run() member.
The start policy attribute indicates whether or not to leave the newly created thread in the interrupted state upon return from start(). Normally, a new thread is released from this interrupt before start() returns. If requested using this attribute, though, the thread can be left in the interrupted state, where it can be released some time later by calling the releaseInterrupt() member of the threaded runnable instance.
The enumerated type,
RWStartPolicy, defines these start policies as:
RW_THR_START_RUNNING — Specifies that a new thread is to be allowed after successful creation and initialization. This is the default start policy.
RW_THR_START_INTERRUPTED — Specifies that a new thread should be left interrupted following start-up and initialization. Interrupted threads can be released when convenient by calling the
releaseInterrupt() member on the same threaded runnable class instance.
The
RWThreadAttribute member functions that are used to manipulate the start policy attribute include:
canGetStartPolicy() — Indicates whether the start policy attribute is supported in the current environment and whether
getStartPolicy() can currently return a legal value. This function always returns
true and has been included for consistency.
isStartPolicySet() — Indicates whether the start policy attribute value is the value that was previously set by a call to
setStartPolicy().
getStartPolicy() — Returns the default start policy value if the attribute value has not yet been set. Otherwise, it returns the value specified in the last call to
setStartPolicy(). The default start policy is available under all circumstances, and is defined as
RW_THR_START_RUNNING.
canSetStartPolicy() — Indicates whether the start policy attribute and attribute value passed as an argument are supported in the current environment. This function always return
true for either of the start policies and has been included for consistency.
setStartPolicy() — Sets the start policy attribute to the value passed as an argument. This function only throws an exception if the value passed is not one of the two legal values.
resetStartPolicy() — Restores the start policy attribute to its default value.
No specific interdependencies exist between the start policy attribute and other scheduling attributes.
The start policy specified by an
RWThreadAttribute can only be used at thread creation. To interrupt an active thread, use the
RWThread member
requestInterrupt() or the
RWThreadSelf member
interrupt().