timers in C++

S

solarin

Im devoloping a simulator for a driver. Every time the simulator
recieves a frame, it must answer with another. One of these frames,
forces to use a few variables during 3 seconds. How I should create a 3
seconds timer? During this time , the simulator and the driver continue
receiving and sending data of course.

Thanks for your support.
 
J

Jaime

If your C++ program will run on Unix/Linux, you can use setitimer in
<sys/time.h>
It can be consulted with "man setitimer" on the command line.
 
S

solarin

Jaime ha escrito:
If your C++ program will run on Unix/Linux, you can use setitimer in
<sys/time.h>
It can be consulted with "man setitimer" on the command line.

Im developing under windows, but thanks for your help.
 
H

Howard

solarin said:
Jaime ha escrito:


Im developing under windows, but thanks for your help.

You'll need to ask in a Windows newsgroup then. Timers are not part of the
C++ language itself, but are supplied by the operating system (and sometimes
wrapped by compiler or third-party vendors, I suppose).

-Howard
 
M

Moonlit

Hi,

One solution is to use mutlithreading. Lookup beginthreadex, mutexes
WaitForSingleObject etc.

Another solution. When reading from file descriptors sockets you can
use(/abuse) 'select'. The last parameter of select is a timeout value i,e.

Set the timeout to 3 seconds.
If anything is received on the descriptors check the time (you can do
precision timing with the multimedia functions of windows) So you know how
long the next wait should be
Handle the incoming messages
Do an select of the remaining 3 seconds (you can check the return value of
select to know if it returned because of timer expiry)

If return because of 3 second elapse do your '3 second thing'

Ad infinitum

--


Regards, Ron AF Greve

http://moonlit.xs4all.nl
 
B

Boris

solarin said:
Im devoloping a simulator for a driver. Every time the simulator
recieves a frame, it must answer with another. One of these frames,
forces to use a few variables during 3 seconds. How I should create a
3 seconds timer? During this time , the simulator and the driver
continue receiving and sending data of course.

There are some timer classes in Boost:
http://www.boost.org/libs/timer/index.html
I never tried them though.

Boris
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top