Timer 9600/s

Discussion in 'C Programming' started by Rafal M, Sep 2, 2005.

  1. Rafal M

    Rafal M Guest

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

    Regards,
    Rafal
    Rafal M, Sep 2, 2005
    #1
    1. Advertising

  2. Rafal M

    Kevin Handy Guest

    Rafal M wrote:
    > 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.

    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Kevin Handy, Sep 2, 2005
    #2
    1. Advertising

  3. Emmanuel Delahaye, Sep 2, 2005
    #3
  4. In article <df9qiu$kd5$>,
    Rafal M <> wrote:
    >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.
    --
    Any sufficiently advanced bug is indistinguishable from a feature.
    -- Rich Kulawiec
    Walter Roberson, Sep 2, 2005
    #4
  5. Rafal M

    Eric Sosman Guest

    Walter Roberson wrote:
    > [...]
    > 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.

    --
    Eric Sosman, Sep 2, 2005
    #5
  6. Rafal M

    Rafal M Guest

    Rafal M wrote:
    > 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");
    }
    }
    Rafal M, Sep 2, 2005
    #6
  7. In article <df9vt6$noq$>,
    Eric Sosman <> wrote:
    >Walter Roberson wrote:
    >> 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.
    --
    'The short version of what Walter said is "You have asked a question
    which has no useful answer, please reconsider the nature of the
    problem you wish to solve".' -- Tony Mantler
    Walter Roberson, Sep 2, 2005
    #7
  8. Rafal M <> writes:
    > Rafal M wrote:
    >> Is it possible to create timer 9600/s in C?

    >
    > 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.

    --
    Keith Thompson (The_Other_Keith) <http://www.ghoti.net/~kst>
    San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
    We must do something. This is something. Therefore, we must do this.
    Keith Thompson, Sep 2, 2005
    #8
  9. Keith Thompson wrote on 02/09/05 :
    > Rafal M <> writes:
    >> hTimer = CreateWaitableTimer(NULL, TRUE, "WaitableTimer");


    > 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
    Emmanuel Delahaye, Sep 2, 2005
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Arnaud
    Replies:
    1
    Views:
    768
    Iwo Mergler
    Feb 18, 2004
  2. Kelsang Wangchuk

    System.Timers.Timer vs. System.Threading.Timer

    Kelsang Wangchuk, Jul 31, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    707
    Kelsang Wangchuk
    Jul 31, 2003
  3. Replies:
    1
    Views:
    1,584
    Steve C. Orr [MVP, MCSD]
    Feb 22, 2005
  4. Simon

    page timer, or redirect timer

    Simon, Nov 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    11,189
    Bruce Barker
    Nov 4, 2005
  5. Replies:
    8
    Views:
    482
    Jorgen Grahn
    Jul 15, 2013
Loading...

Share This Page