Multithreaded resource management
I''ve created a monster...
In the process of writing the code for multithreading I at some point decided to writing the file loading portion as a seperate queue driven thread. This works fine now, but I''m at a loss as to how I''d best use it.
Example, starting a level you load 100 textures, 20 sounds, 16 models and the map. The textures are jpeg, the sound (hopefully) will be mp3, the map in a zip. The code to drive this loads the files and places a pointer to the data on a queue. A switch function(pluggable factory) works the queue and sends each file to the relevant processing function (jpeg decompression etc). This should work great, with file loading occuring at the same time as decompression at the same time at the network setup is occuring. Problem is, what the best way to find out if all my resoures have loaded? Perhaps an slist that stores all the message ID''s I used to load the resources, whihc as each one completes I delete from the list, all are loaded when the list is empty?
Any one have any comments on this ( not bad ones it''s almost finsihed coding)
gimp
Chris Brodie
July 28, 2000 09:40 AM
Like Void pointed out using CreateEvent in conjunction with WaitForSingleObject is a good solution. Check out the msdn docs on those.
Also, if your thread function has access to the window handle of the calling thread (stuffed in your LPARAM), then you can post a message back to that thread letting you know when your load code is done.
Better yet, WaitForMultipleObjects. You can have your main thread (the one that spawns all the workers) wait on all signal. This requires the signals to be defined before the wait statement. I believe if one of your threads encounters a problem, you can delete one of the events and then the Wait will fail.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement