delay

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • asit

    #1

    delay

    In my multi threaded application(win dows), I have several infinite
    loop(though it's not good to have...but I need them). Hence they eat
    nearly 98% of CPU time(it shows in task manager).

    I have decided to put a delay of 200 ms in the program. But
    unfortunately my Compiler(Borlan d 5.5) is not providing any such
    functionalities .

    In my research, I found that many (lame) people put delay by putting
    unnecessary instructions in the delay block....like this

    void delay()
    {
    int i=0,j=10;
    for(i=0;i<12345 678;i++)
    j *=j;
    }

    But it won't do my job. But I have found that by doing some kind of
    signal handling, I can create my delay function.

    Does such functionality is available in windows ????
    How can I implement it ????

  • Antoninus Twink

    #2
    Re: delay

    On 7 Oct 2008 at 7:13, asit wrote:
    In my multi threaded application(win dows), I have several infinite
    loop(though it's not good to have...but I need them). Hence they eat
    nearly 98% of CPU time(it shows in task manager).
    >
    I have decided to put a delay of 200 ms in the program. But
    unfortunately my Compiler(Borlan d 5.5) is not providing any such
    functionalities .
    >
    But it won't do my job. But I have found that by doing some kind of
    signal handling, I can create my delay function.
    >
    Does such functionality is available in windows ????
    How can I implement it ????
    On POSIX systems, the function you're looking for is called sleep(3) and
    can be implemented using the SIGALRM signal.

    Doing a Google search for
    "Windows API" sleep
    shows that the corresponding Windows function is called Sleep with a
    capital S, and takes a long int argument specifying the length of time
    to wait in milliseconds.

    Comment

    • Ian Collins

      #3
      Re: delay

      Antoninus Twink wrote:
      On 7 Oct 2008 at 7:13, asit wrote:
      >In my multi threaded application(win dows), I have several infinite
      >loop(though it's not good to have...but I need them). Hence they eat
      >nearly 98% of CPU time(it shows in task manager).
      >>
      >I have decided to put a delay of 200 ms in the program. But
      >unfortunatel y my Compiler(Borlan d 5.5) is not providing any such
      >functionalitie s.
      >>
      >But it won't do my job. But I have found that by doing some kind of
      >signal handling, I can create my delay function.
      >>
      >Does such functionality is available in windows ????
      >How can I implement it ????
      >
      On POSIX systems, the function you're looking for is called sleep(3) and
      can be implemented using the SIGALRM signal.
      >
      Utter nonsense. sleep(3) suspendeds execution for a number of seconds.
      The correct POSIX function would be nanosleep(). SIGALRM is a total
      red herring.

      --
      Ian Collins.

      Comment

      • Antoninus Twink

        #4
        Re: delay

        On 7 Oct 2008 at 7:48, Ian Collins wrote:
        Antoninus Twink wrote:
        >On POSIX systems, the function you're looking for is called sleep(3)
        >and can be implemented using the SIGALRM signal.
        >>
        Utter nonsense. sleep(3) suspendeds execution for a number of
        seconds. The correct POSIX function would be nanosleep().
        As usual, you deliberately misunderstand.

        The OP's question was about Windows, and the only point of mentioning
        POSIX was to find the correct synonymn for delay (namely sleep) that
        results in a successful Google search.

        Try googling
        "Windows API" nanosleep
        and see how useful the results are.
        SIGALRM is a total red herring.
        The OP asked whether delay functions can be implemented using signals.
        In principle, the answer is clearly yes, as demonstrated by alarm(2).
        The fact that its argument is a time in seconds doesn't change the fact
        that it works by delivering a SIGALRM to the calling process.

        Comment

        • asit

          #5
          Re: delay

          The problem is that i don't use Visual C++, I use Borland C++ 5.0.

          Comment

          • Antoninus Twink

            #6
            Re: delay

            On 7 Oct 2008 at 8:33, asit wrote:
            The problem is that i don't use Visual C++, I use Borland C++ 5.0.
            Surely you can access the Windows standard library with any C or C++
            compiler?

            Comment

            • Nick Keighley

              #7
              Re: delay

              On 7 Oct, 09:33, asit <lipu...@gmail. comwrote:
              The problem is that i don't use Visual C++, I use Borland C++ 5.0.
              the problem is you are on the wrong news group.
              Please post your problem to a suitable Microsoft newsgroup.

              Comment

              • asit

                #8
                Re: delay

                On Oct 7, 1:46 pm, Nick Keighley <nick_keighley_ nos...@hotmail. com>
                wrote:
                On 7 Oct, 09:33, asit <lipu...@gmail. comwrote:
                >
                The problem is that i don't use Visual C++, I use Borland C++ 5.0.
                >
                the problem is you are on the wrong news group.
                Please post your problem to a suitable Microsoft newsgroup.
                thanx friends....

                finally I solved my problem.
                the required function is Sleep(int milisec)
                now my keylogger is not eating much resources ...

                Comment

                • Nate Eldredge

                  #9
                  Re: delay

                  [off-topic]

                  Antoninus Twink <nospam@nospam. invalidwrites:
                  On 7 Oct 2008 at 7:48, Ian Collins wrote:
                  >
                  >SIGALRM is a total red herring.
                  >
                  The OP asked whether delay functions can be implemented using signals.
                  In principle, the answer is clearly yes, as demonstrated by alarm(2).
                  The fact that its argument is a time in seconds doesn't change the fact
                  that it works by delivering a SIGALRM to the calling process.
                  Certainly sleep(3) can be implemented via alarm(2), and historically
                  has been, but isn't always. On my system it just calls nanosleep(2).

                  Comment

                  • jacob navia

                    #10
                    Re: delay

                    Antoninus Twink wrote:
                    On 7 Oct 2008 at 8:33, asit wrote:
                    >The problem is that i don't use Visual C++, I use Borland C++ 5.0.
                    >
                    Surely you can access the Windows standard library with any C or C++
                    compiler?
                    >
                    Sleep is a basic windows function accessible from both compilers.

                    --
                    jacob navia
                    jacob at jacob point remcomp point fr
                    logiciels/informatique
                    http://www.cs.virginia.edu/~lcc-win32

                    Comment

                    • Keith Thompson

                      #11
                      Re: delay

                      asit <lipun4u@gmail. comwrites:
                      In my multi threaded application(win dows), I have several infinite
                      loop(though it's not good to have...but I need them). Hence they eat
                      nearly 98% of CPU time(it shows in task manager).
                      >
                      I have decided to put a delay of 200 ms in the program. But
                      unfortunately my Compiler(Borlan d 5.5) is not providing any such
                      functionalities .
                      [...]

                      Questions about Windows-specific functions will generally get better
                      and quicker answers in comp.os.ms-windows.program mer.win32 or in one
                      of the microsoft.* groups.

                      --
                      Keith Thompson (The_Other_Keit h) kst-u@mib.org <http://www.ghoti.net/~kst>
                      Nokia
                      "We must do something. This is something. Therefore, we must do this."
                      -- Antony Jay and Jonathan Lynn, "Yes Minister"

                      Comment

                      • CBFalconer

                        #12
                        Re: delay

                        jacob navia wrote:
                        Antoninus Twink wrote:
                        >asit wrote:
                        >>
                        >>The problem is that i don't use Visual C++, I use Borland C++ 5.0.
                        >>
                        >Surely you can access the Windows standard library with any C or
                        >C++ compiler?
                        >
                        Sleep is a basic windows function accessible from both compilers.
                        The point is the 'sleep' is not an available function in standard
                        C. If you want it available, go to a newsgroup that deals with
                        whatever non-standard system you are using. It is off-topic on
                        c.l.c. You will have a hard time accessing the Windows standard
                        library on a Linux system, for example.

                        --
                        [mail]: Chuck F (cbfalconer at maineline dot net)
                        [page]: <http://cbfalconer.home .att.net>
                        Try the download section.

                        Comment

                        Working...