Timer 9600/s

K

Kevin Handy

Rafal said:
Hi,
Is it possible to create timer 9600/s in C?

Depends on your filesystem. Many do not allow spaces
or slashes in the file names. However, you will need
to ask on a newsgroup dedicated to you OS, as this one
does not handle OS based problems.
 
W

Walter Roberson

Is it possible to create timer 9600/s in C?

If you mean a timer that invokes a signal handler 9600 times every
second, then the answer is "No, not portably".

If you mean a timer that is accurate to within 1/9600 of a second
when it is examined, then the answer is "No, not portably".

If you mean a timer that can signal an event after 9600 seconds,
then the answer is "No, not portably".

Portable C does not offer any facilities for triggering actions
after particular lengths of time (at any precision), and the
highest resolution time-of-day counter it has is clock()
which increments CLOCKS_PER_SEC times a second. I do not see any bounds
imposed on CLOCKS_PER_SEC at the moment; if I recall correctly
one of the standards imposes a minimum bound on CLOCKS_PER_SEC,
but I do not recall which standard it is.
 
E

Eric Sosman

Walter said:
[...]
Portable C does not offer any facilities for triggering actions
after particular lengths of time (at any precision), and the
highest resolution time-of-day counter it has is clock()
which increments CLOCKS_PER_SEC times a second. [...]

First, clock() measures CPU time, not time of day.
For the latter, you need time().

Second, the clock() value does not necessarily increment
CLOCKS_PER_SEC times per second, nor even per CPU second.
The value is *stated* in units of 1/CLOCKS_PER_SEC seconds,
but that doesn't imply that it's *measured* in those units.
 
R

Rafal M

Rafal said:
Hi,
Is it possible to create timer 9600/s in C?

Regards,
Rafal

Why 100us not work (is slow)?

HANDLE hTimer = NULL;
LARGE_INTEGER liDueTime;

liDueTime.QuadPart=-1000 // 100ns*1000 =100us

// Create a waitable timer.
hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");


while (true)
{
SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0);
if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
{
printf("failed");
}
else
{
printf("T");
}
}
 
W

Walter Roberson

Walter said:
Portable C does not offer any facilities for triggering actions
after particular lengths of time (at any precision), and the
highest resolution time-of-day counter it has is clock()
which increments CLOCKS_PER_SEC times a second. [...]
First, clock() measures CPU time, not time of day.
For the latter, you need time().

Sorry, brain lapse.
Second, the clock() value does not necessarily increment
CLOCKS_PER_SEC times per second, nor even per CPU second.
The value is *stated* in units of 1/CLOCKS_PER_SEC seconds,
but that doesn't imply that it's *measured* in those units.

You are of course correct; at the time of my writing I was casting
around for better wording but couldn't think of any then.
 
K

Keith Thompson

Rafal M said:
Why 100us not work (is slow)?

HANDLE hTimer = NULL;
LARGE_INTEGER liDueTime;

liDueTime.QuadPart=-1000 // 100ns*1000 =100us

// Create a waitable timer.
hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");


while (true)
{
SetWaitableTimer(hTimer, &liDueTime, 0, NULL, NULL, 0);
if (WaitForSingleObject(hTimer, INFINITE) != WAIT_OBJECT_0)
{
printf("failed");
}
else
{
printf("T");
}
}

That code fragment is extremely system-specific, and therefore
off-topic in this newsgroup. I don't even know what system it applies
to.
 
E

Emmanuel Delahaye

Keith Thompson wrote on 02/09/05 :
That code fragment is extremely system-specific, and therefore
off-topic in this newsgroup. I don't even know what system it applies
to.

It probably is Microsoft (MSDN).

http://msdn.microsoft.com/library/d...ry/en-us/dllproc/base/createwaitabletimer.asp

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"It's specified. But anyone who writes code like that should be
transmogrified into earthworms and fed to ducks." -- Chris Dollin CLC
 

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,774
Messages
2,569,596
Members
45,130
Latest member
MitchellTe
Top