Menu

GCC code with setitimer and itimerval

2009-03-23
2012-09-26
  • John Noneman

    John Noneman - 2009-03-23

    I have some GCC code that uses "itimerval" and "setitimer". I have searched the header files in Dev-Cpp, but cannot find it. The code will not compile. What am I missing?

     
    • Wayne Keen

      Wayne Keen - 2009-03-23

      Some googling about seemed to show that those functions are no implemented in MinGW (the environment that lets the GCC compiler work under windows).

      Then again it is Monday, and I am probably dumber than a pet rock right now

      Wayne

       
    • Wayne Keen

      Wayne Keen - 2009-03-23

      I did find setitimer in a seperate MinGW install I have, it was in SDL_timer.h

      Wayne

       
    • cpns

      cpns - 2009-03-23

      > What am I missing?

      Linux, the GNU C library.

      While MinGW/GCC is an implementation of the GNU compiler, it does not use the GNU C library. The GNU C library has deep dependencies on the Linux OS. You can use it on Windows by using Cygwin instead of MinGW. Cygwin uses a Linux emulation layer on Windows to allow the GNU C library to work. However Cygwin is a sledgehammer for a nut in most cases; you are better off porting the code than trying to emulate an entire OS just for two functions.

      That said, emulating this functionality in Windows is troublesome since Windows does not support signals in quite the way Linux does. You can use Windows timers, but they rely on Windows messaging which you would normally only use in an event-driven GUI application. Making a console app event driven (i.e having a windows messaging loop) is possible, but it would probably change the entire design of your app.

      A better solution is to have a separate thread that sleeps for brief periods, wakes up, checks the time and sends a message to the applications main thread using an appropriate IPC mechanism. All this might seem a lot of work, but bear in mind that you only need write such code once and then reuse it in any applications that need it. You could even use it to emulate the setitimer() interface.

      Of course if your needs are simple, you may simply be able to use Sleep().

      The .NET framework provides the System.Timers.Timer class (as well as a couple of other timer classes), which probably does what you need, but in that case MinGW won't help you at all!

      Clifford

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.