Doing stuff while drawing is halted

I notice that when drawing is halted, e.g., an app is in the background, Allegro blocks until you return. The problem with that for me is that RakNet is paranoid and if it does not hear from me in a timely manner, it will drop my connection.

Therefore, if a user goes to the background for about 5 seconds, they get kicked from the server which is not desired.

Is there some way I can continue to call my net->tick(); function while my App is in the background? I can always start a thread to do it, but I would prefer not to involve multithreading if possible.

Thomas Fjellstrom

Do you know where it is blocking? al_wait_for_event perhaps? I know you get an event when you switch out, and drawing is halted.. if you notice that, you can probably just skip the al_wait_for_event and just start polling raknet occasionally?

Or instead of a plain al_wait_for_event you use al_wait_for_event_timed to let it timeout and then process raknet.


Thanks! al_wait_for_event_timed was just what I was looking for! The reason I need it is I need to receive the event when things resume.

Thomas Fjellstrom

You should always get a resume event when things resume.


From what I can see from testing, a few seconds after calling al_acknowledge_drawing_halt Allegro just pauses all execution on all my threads, I even tried creating a thread that jus prints hello and even that stopped printing a few seconds later and started printing again when I returned. It is not iOS doing this, I made a test and eliminating Allegro lets me do stuff when I'm in the background.

So right now I have to way to keep the network thread alive :(

If I omit acknowledging the halt, my networking keeps running fine, but then I can never get the resume because I never called the acknowledge_halt...

Odd thing though is I don't see anything in Allegro's source that indicates it locks threads on drawing halt.


ALLEGRO_EVENT_DISPLAY_HALT_DRAWING is done whenever ios sends this to the application: [1]


If the method does not return before time runs out your app is terminated and purged from memory.

So no, just continuing is not an option, according to Apple. You probably have to register your app as a special background application (those displaying a little icon at the top) to keep any network activity while it is switched out. I don't know details how to do it, but a normal application definitely cannot keep running in the back under iOS.


Thanks for the info. I was not aware of how all that worked.

Thomas Fjellstrom

Ah, I wasn't thinking this was on mobile. Yeah, you basically need to take that into account...

Thread #615114. Printed from