Simulating "system idle" events in Carbon applications

Post: #1
thanks to some great posts in this forum and to OneSadCookie's sample code for AGL, I've got a first working port of my emulator Tickle ( as a Carbon application for Mac OS X, although with no audio yet.
Now, the very simple architecture I already use on Windows and Linux is based on receiving "idle" events from the system, and I would like to reuse that on the Mac too.
Apparently, the system does not provide such events "out of the box", so they have to be produced manually. Here's what I'm doing. Before calling RunApplicationEventLoop(), I create an 'IDLE' event and post it to the main queue. This event is handled by the application event handler, which immediately reposts it on the same queue thus generating an endless stream of 'IDLE' events.
From what I can see, this method works very well, and gives me several thousands events per second... more than I need actually! :-)
Ok, now I have a couple of questions:
1) is there something wrong with the above approach? Some solutions I found on the net are considerably more complicated and I wonder if I'm missing something (being still a beginner for Mac programming);
2) is it ok to call CreateEvent just once or do I have to create a separate event for each post?
Thanks for your help and BTW this is really an amazing place for Mac knowledge!
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #2
Personally, I'd be doing this with a timer... but if your approach is working, there's probably nothing wrong with it Smile
Quote this message in a reply
Post: #3
Hey good advice... I just switched to a fast timer and it seems to work better actually! Smile

One problem of the method I posted is idle messages do not get dispatched when the system is busy in some "internal" operation, e.g. when you drag the window around. Timers do not suffer from this.

There is one piece of information I would like to know though: what is the "guaranteed" resolution of those timers?
Quote this message in a reply
Posts: 869
Joined: 2003.01
Post: #4
There isn't any guaranteed resolution. If the system hangs on VM paging, for example, you're SOL. If you want guaranteed resolution, you need to use a real-time OS, or look into what OS X has to offer in that regard.
Quote this message in a reply
Posts: 5,143
Joined: 2002.04
Post: #5
There is no guaranteed resolution. They will fire as often as possible, up to the requested rate.
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  [For David, aarku] Carbon Events OneSadCookie 4 5,665 Mar 5, 2013 10:20 PM
Last Post: SethWillits
  Carbon events in windowed/full screen mode. Help needed. Anton Petrov 1 3,759 Dec 18, 2008 05:35 AM
Last Post: DoG
  Simulating a vehicle onterrain (OpenGL) Danny77uk 4 3,368 Feb 7, 2008 09:08 AM
Last Post: Danny77uk
  Carbon Key Events Nickolei 7 5,305 Nov 17, 2002 03:37 PM
Last Post: codemattic
  Carbon Keyboard Events IBethune 7 5,956 Oct 22, 2002 05:58 AM
Last Post: IBethune