1.08.2012

Events

So my rewrite of the qmutex apparently works. Locking, re-locking and unlocking worked as expected and even my older test results were as expected, too. So I assume this works fine and that I'll now be able to to some nice event framework around it. I've been thinking around since I woke up and I think it's the best idea to only use this system to continue a set of threads, not doing any logic inbetween to avoid any sort of waiting. I've thought about using some sort of event type system where all threads look if it's the right even and so on, but using this consistently is hardly of any performance advantage. I mean imagine 30 threads all sequentially looking for a matching type each time an event happens, one after another, you'll need to wait for all those threads to check and cycle. So, combined with the fact that there maybe only one sending thread but 10 different event types, you'll end up with 30x10 type checks for only 10 events of 10 different types. 300 checks, isn't that a bit too much? My idea is to create a single qmutex for each event and only notify those threads waiting on the specific event type to fire. Thus you get only 10 interruptions with no per-thread checks at all. These only this very small overhead when passing control to the other threads (for example, three threads each wait for the same type type to fire and you'll only need to wait for the number of threads that enlisted for waiting - 30 to be exact). Way more efficient for obvious reasons. I'm once again not too fond of those highly theoric constructs they did over 30 years ago. And they still teach it universities cause they are not as complex when assuming they are atomatic parts of Java. *sigh* Whatever.

So I'm going to design some interface for this. I'm confident that'll have the complete ressource system working until Thursday or so. And that means that I'll finally be able to start my work on the world map stuff and the renderer. What an odyssey! Didn't expect it to take that long. But atleast I'm quite good at writing multithreaded stuff, you know. I think that's worth it, definitely.

No comments: