Paul Jones <email@example.com> wrote:
Thanks for the replies. To clarify the loop takes approximately 0.5ms and
cannot block, its just number crunching. time() appears to be the best way
If that’s the case, then you can check the time() only once ever
several hundred iterations to increase efficiency – time() gives you
one second resolution, this 1/0.5ms = 2000 iterations per second – there’s
no need to check the time() 2000 times per second
“Bill Caroselli” <> firstname.lastname@example.org> > wrote in message
news:b28v4b$hqm$> email@example.com> …
Robert Krten <> firstname.lastname@example.org> > wrote:
Paul Jones <> email@example.com> > wrote:
I would like to have a loop that exits after a certain amount of time
regardless of how many times the loop has executed. For example:
while(loop_execution_time < Tmax)
// Run loop
Is there a good way of performing this in QNX? I thought I could set
one shot timer that sent a pulse when the time was up but I have to
the pulse syncronously so the loop cannot run. Is there an
version of a pulse or is it best to check the current time at the end
loop and exit if it’s greater than Tmax?
Why not check the current time? Unless each individual iteration
of the loops takes a long time, and you therefore aren’t getting the
granularity you need, I’d just check the current time.
If you do need to “interrupt” the processing in the middle of the loop,
much as I hate signals, look at “alarm()” >
I agree with Robert, except, the issue might not just be granularity.
If your loop can block for any reason, and you may want to kill your
loop in the middle of an iteration, then as Robert said, alarm().
time_t Tmax = time(0) + some_max_number_of_seconds;
while( time(0) < Tmax )
// do something that someone thinks is useful.
// NOTE: time(0) returns now is seconds
Bill Caroselli – Q-TPS Consulting
Robert Krten, PARSE Software Devices +1 613 599 8316.
Realtime Systems Architecture, Books, Video-based and Instructor-led
Training and Consulting at www.parse.com.
Email my initials at parse dot com.