wait in c

P

Pierpaolo

hi!! Is there a function in order to wait for a time in milliseconds??
Thanks in advance
 
T

thomas.mertes

Hello

There is no wait_milliseconds() or wait_mycroseconds() function
in the C library or under UNIX/Linux. Windows has the Sleep()
function to wait for milliseconds, but it is not very precise.

Under UNIX/Linux there are signals and the setitimer() function
can be called to issue a signal after an amount of time measured
in seconds and mycroseconds.

If you want to see how this is programmed, look at Seed7
(http://seed7.sourceforge.net).

In the file seed7/src/tim_unx.c (found in seed7_05_20060111.tgz
or a newer version) you find the Seed7 time driver.

The function await_time() uses signals (with sigaction(),
sigsetjmp() and setitimer() or signal(), setjmp() and setitimer() )
to wait for a duration expressed in seconds and mycroseconds.

The whole await_time() function waits for a time (not a duration)
expressed in seconds and mycroseconds. This allows Seed7
to have an await() function which can wait for very small
durations. The example program panic.sd7 waits in 30
millisecond intervals to show a smooth motion of the monsters.

I hope this can help you

Greetings Thomas Mertes

Seed7 Homepage: http://seed7.sourceforge.net
Wikipedia: http://en.wikipedia.org/wiki/Seed7
Project page: http://sourceforge.net/projects/seed7
 
K

Keith Thompson

There is no wait_milliseconds() or wait_mycroseconds() function
in the C library or under UNIX/Linux. Windows has the Sleep()
function to wait for milliseconds, but it is not very precise.

There is no wait function of any kind in standard C. UNIX/Linux
solutions can be discussed in comp.unix.programmer; Windows solutions
can be discussed in a Windows group, perhaps
comp.os.ms-windows.programmer.win32. Both of those groups are full of
experts who know far more about these solutions than we do here. (In
some cases, they may be the same people.)

The C FAQ covers this issue in question 19.37, including pointers to
system-specific functions that the OP can investigate further.

Going into a lot of detail about system-specific features is generally
discouraged here, for a number of reasons that I won't go into.

Finally, it's important to provide some context when you post a
followup. Please read <http://cfaj.freeshell.org/google/>.
 
L

Logan Shaw

There is no wait_milliseconds() or wait_mycroseconds() function
in the C library or under UNIX/Linux.

On most Unix systems, there is always this approach:

select(0, NULL, NULL, NULL, & my_timeval_struct);

- Logan
 

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,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top