Setting a delay
Typically, you set a delay on a clock to prevent a thread from being processed until a certain time. When you set a delay, the thread is delayed until the specified time is in the clock's past (directionally less than the clock time) or until the delay is canceled. There are two types of delays:
- DelayUntil returns when the current time on the clock is greater than or equal to the delay time.
- DelayFor returns when the current time on the clock is greater than or equal to the start time plus the delay time. DelayFor calls the clock's Now function to determine the start time, and then calls DelayUntil to set the delay.
When a delay returns, use the time returned from TClock::Now to determine what to do next. For example, if the flow of time has reversed direction, you might want to set another delay and not continue processing until time is flowing forward again; however, if the flow of time has not reversed, processing can continue normally. You have to call Now to determine the direction that time is flowing. Now is normally the fastest clock function and returns the most accurate time.
You should never make assumptions about the time because it can be affected by many factors. For example:
- The time might be reset.
- The direction of the flow of time might be reversed.
- A thread might not unblock exactly at the specified time because a higher priority thread was processed first.
For information about one way to handle the second case, see "Programming around time flowing backward" on page 86.
[Contents]
[Previous]
[Next]
Click the icon to mail questions or corrections about this material to Taligent personnel.
Copyright©1995 Taligent,Inc. All rights reserved.
Generated with WebMaker