Friday, January 13, 2006

What's an Async Task? (Is it good with jam?)

You may have seen a crpytic message like "async task jammed" or "thread timed out" with X-plane 8.20 or 8.30, after which the sim quits. Here's what's going on and what we're trying to do to fix this.

X-Plane offloads part of the scenery load process to a second processor. (If you don't have a second CPU, the first one does the work, but the operating system switches between the two tasks automatically.) For example, X-Plane "outsources" the work of turning a road (which is just a line segment in a scenery file) into real 3-d roads using the second CPU.

X-plane puts a request for the roads out to the second CPU, and then every frame it checks to see if it's done. If the roads are processed, it can then send them to the video card and go on to the next thing to be done. If the roads are not finished - no biggie - it just checks again on the next frame.

Now here's where the trouble begins: sometimes X-Plane needs the outsourced work to be done immediately. For example, when we load new scenery we have to recycle the memory from the old scenery. This requires the work of building the roads on the old scenery to be done! When this happens, X-Plane waits (up to 2 minutes) for the background work to finish.

If after 2 minutes the work is not done, X-Plane gives up and puts up a cryptic message like "async task jammed" or "thread timed out". (In 830 beta 11 the message should be less cryptic.) I must admit: I do not understand how this condition happens; it has never happened on my machine or Austin's.

Here's what we're doing to alleviate the problem: in X-Plane 830 you can turn off the "load scenery in the background" option. When this happens, rather than outsource jobs to the second CPU, X-Plane will do the work immediately. This will have two effects:
  1. There will be slight pauses as you fly while x-plane stops and builds roads, etc.
  2. There is no way that we can get stuck waiting for the second CPU, because it won't be used.
Besides turning off this option, you can reduce the amount of stuttering (either with background loading on or off) by decreasing the amount of roads and objects. For example, on my G5, the sim flies pretty smoothly on "default" settings with background loading on or off. But on "insane" settings the sim is still smooth with background loading on and stutters visciously with background loading off.

I hope to get the background code to be more reliable in 840, but in the meantime you should be able to fly (etiher with or without background loading) in 830 with reasonable results if you set your rendering settings appropriately.

No comments: