ReceiveNextEvent problem

Hello,
I am writing an application where I use ReceiveNextEvent to manually capture my events. The problem I am having is that when I run two instances of my program (foo) simultaneously. When I do this, the area where the foo instances overlap, flickers.
I tried running foo and a test glut program, which uses the glut event loop, simultaneously. No flickering.
There must be something wrong with how I am using carbon/agl for my application. I have looked at many examples and I cannot see what I am doing wrong.
I would really appreciate if someone sees the problem with my code and could help me.
Here is a code sample where I have stripped out all the application code but the bare minimum. When I run two instances of this, I get the flickering.
--------------------------

My application has a lot of generic C++ and OpenGL code with only a small amount of code to create a container window. On windows, it uses the windows api and on linux it uses X windows. When I wrote the mac code using agl/carbon, it is only about 150 lines of code to write the container window. So I cannot easily rewrite the 1000s of lines of C++ code into Objective C, just to get the less than 200 lines of windowing functionality to work.
That is the reason I was trying to get Carbon to work.
So going forward, if Apple is not going to support Carbon, is there a way for me to write the windowing module in Cocos (ObjectiveC) and link it with the C++ code compiled with gcc?
I am sorry if this seems like a silly question. I have only been learning to program on macs for a few months. So if someone can at least point me in a direction where someone else has solved this same issue, it would be of great help. Thanks!

You don't need to re-write any of your existing code in Objective-C for Cocoa. You can look at Cocoa like .NET, where you'd only use .NET for your basic windowing code, then call out to your C++ codebase for your game.

Instead of using Cocoa, you could look into using SDL instead, for your windowing module. Actually, you could use SDL for Windows/Linux/Mac and save yourself some hassle, if it'd suit your needs.

C and ObjC can be freely intermixed in .m files, C++ and ObjC can be freely intermixed in .mm files. There is no problem with doing exactly what you do on the other two platforms, but using Cocoa. The biggest issue is likely to be if you've assumed that the OS works a particular way (eg. having complete control over the event loop, or assuming you can do anything on any thread).

I am using a manual event loop now on windows and linux, so I can control the refresh based on physics, controller state, etc. For what I want to do, it sounds like SDL is the best implementation path for me to use on the mac. And as jake said, it is portable between platforms, which means I can use the same windows/event code rather than implementing in ms windows, xwindows or cocoa depending on the os.
Thanks for your responses.