Assignment 3 - CS3120, Summer 2003

Due date: Wednesday, June 18, 2003

 

This assignment can be done in pairs, but pairs must be decided and the pairing submitted prior to the beginning of class, Friday, June 13th.

 

For the following situation, devise a synchronization scheme between the loading process and the main process that will meet the main requirement of CPU efficiency and guard the critical sections for the queues.  Your submission should include the detailed pseudo code necessary to implement the scheme, including initialization of shared data .  A diagram showing the interaction of the processes will aide in the understanding of your solution.  There should also be a discussion section that explains why you chose the concurrency mechanisms you did, and an argument about how your solution is correct in terms of mutual exclusion, progress and bounded waiting both for the critical sections and the synchronization of the loading process.

 

This is a real-life scenario from a game engine currently being designed.  The summary of the situation is:

 

o        Need asynchronous file i/o with callbacks when operations complete so that the game can do things like start loading data, and then when some of the data is loaded it can start doing the work it needs to do on the data while other data is loading in the background.  The problem with games is that load times really hurt a game's popularity, so you really have to optimize your loading.

 

o        One way to do that is make it so you are never waiting on hardware to finish loading something.  You load a little at a time, and then process the data while the rest of the data is being loaded.  For example you could start loading a texture, then update your screen to do some fancy loading display that entertains the player while loading is going on, then when your texture is loaded you can start loading the next file you need and then go onto decompressing your texture and storing it in video memory.

 

o        There is a loading process and a file wrapper class called Cfile.  The user issues a read request with CFIle, and then that request is queued on a queue of pending file i/o requests (each one being either read, write or seek).

 

o        The loading process checks the queue of pending requests, gets the oldest one, and acts on the request.

 

o        When the request is finished the loading process stores the results on the completed i/o requests queue.

 

o        In the game's main loop a static method of Cfile is called every frame to "service" the file i/o system, and any completed requests on the second queue are dealt with.

 

o        A separate process is needed so that loading can be asynchronous.  Critical sections are needed so that two processes can't operate on the queues at the same time.  There needs to be a synchronization mechanism to activate the loading process because the loading thread should not be taking up CPU resources when there is nothing that needs to be loaded.