May 18 2009
In most modern games, asynchronous file loading is a standard requirement. This is especially true for open world games or games which never want to show a loading screen. On the surface, it seems like an easy thing to do: spawn a new thread and load files on request. However, there are a few complications which get in the way.
One of the most obvious issues is knowing when the file has actually been loaded. In an asynch environment, you issue a request, and some time later, the request is fulfilled. Most systems return a handle which the game can check periodically to see if the data has been read. This is fairly easy to implement, works well in a multithreaded environment, and is pretty easy to debug. Other alternatives are to use a callback mechanism or put the calling thread to sleep until the data is loaded. The sleep option is usually done in custom scripting languages, instead of trying to do it in C++.