Sigalrm routine using MS CL compiler

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sonias
    New Member
    • Mar 2010
    • 3

    Sigalrm routine using MS CL compiler

    Hi,
    In Linux I can use the "sigalrm" to set a timer with certain set time and start the main program and when the time is up the main program in interrupted and the program exit, but this signal is not available in MS CL compiler can any one help with a sample code.

    Thanks in advance.
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    You could create a thread that sleeps for a set time, and upon waking, forces the program to exit. Note that this will not be an exact amount of time; it depends on how much time there is between time up and the thread waking.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      You could possible use a waitable timer via

      CreateWaitableT imer
      SetWaitableTime r

      To just callback a function when the time is up.

      Comment

      • sonias
        New Member
        • Mar 2010
        • 3

        #4
        Sigalrm routine using MS CL compiler

        Hi jkmyoung,
        Thanks for your reply - I am new to threads can you help simple timer thread example ?

        Regards,

        Comment

        • jkmyoung
          Recognized Expert Top Contributor
          • Mar 2006
          • 2057

          #5
          Thread sleep example
          So in the thread's function, after the call to sleep is done, have it interrupt the program.
          Your main code goes after newThread->Start();

          Comment

          • sonias
            New Member
            • Mar 2010
            • 3

            #6
            Sigalrm routine using MS CL compiler

            Hi,
            Thanks for reply I am using MS command line (cl) c compiler - not c++

            Comment

            Working...