mmozeiko
That could mean your other threads were waiting on some resource (mutex, critical section, etc..) that was locked by I/O thread.
I forgot to mention that the original implementation worked well on the i7, under win7. (IF I did set other priorities than the "intuitive" once. Like I ended up using Above normal for both threads, then it worked like butter. I seem to recall it also worked well if I did not set any priorities).
However, when running in XP the entire thing broke down, whatever I did. It slowed to a crawl. So that's why I even mention it. On the i7, threading usually works very well. Surprisingly well I would say. And I have now since long changed the code so it works for both cases. I was just recalling it, when reading your previous reply.
mmozeiko
Or some other issue, who knows what code you wrote... Without seeing actual code it's just a lot of guessing and "what if".
Yes true. But the problem is that if I let you see the code, you would probably ask me to be payed to read it, and then you would ask for a raise. Because its assembly code, and it's pretty complex. The task it is doing is relatively simple to explain, but the code is optimized on many levels, including dynamic queuing and requeuing of graphical elements. Like it can abort itself at once, and reprioritize which graphical elements are drawn, based on user input. And it is doing this inside a component that is a tree-based structure, that has also a treebased graphical structure. It has one tree for its data, and another for displaying of the graphics. In short. You just have to take my word for it.
And this is a problem. Implementing simple threads is very easy to get right. And talking about complex things is close to impossible. Just like I think you are saying.
mmozeiko
Work must be correctly divided between threads to benefit from multithreading.
This last statement left me a little confused. On the one hand, you say that my usecase from above (The test code) is typically code that does not scale well to paralellization. Yet the paralellization seems damn near perfectly balanced, to my eyes. Which is also what I would expect.
And it would also resemple the task I wrote it for testing, writing a software backbuffer in paralell. It seems I can get a 4 times speedup of updating the backbuffer this way. Which right now would give my code a significant needed boost.
(I forgot to mention that this testcode also updates a progressbar for each thread, each time it has finished the loop. So it adds 1 to each integer in a loop, then updates the progress. This will explain if the code is slower than you expect, but I think it didn't really matter to mention it, since the threads still scale almost perfectly, on 4 cores.
I like to ask a few questions on the use of Events. If you care to consider them.
Yesterday I found I could with much ease port my physics code to 4 cores. This made a significant difference, and I havent even begun the work to optimize how it is scaled. I just devided the tasks on 4 cores, and then I wait for the cores to finish.
When they have finished their work, they SET an event, and the mainthread waits for those 4 events to be set, before it continues. This initially seems to work perfectly. And it made the physics so fast, that I now could easily double the amount of work done. Therefore my drawingcode went from using around 20-30% of the frametime, to using about 50% of the frametime. But it still not only pushed the FPS to a steady 30hz, but it also reached 60, doing 4000 units on the screen.
This made my head boil with excitement when I saw it. So I immidiatly went ahead and did the same for the sorting of the entities, which is done just before drawing them.
But now I suddenly got strange behaviour. It actually seemed like the cores (threads) was continuing doing physics even though they should be waiting. (I use another Event in each thread for the thread to wait until its workqueue has been refilled).
My question for you is if Event are the right way to do this kind of thing?
Is it for instance possible for a thread to first CLEAR the "working" flag, and then SET the event, and then for the mainthread, waiting for the event to become signaled (set) to still read the "working" flag as still set? (While the thread now stuck waiting for the QUUEFILLED event?)
Because that is what is appear to be happening. But it happens very very seldom. For several seconds, everything works well, and then suddenly the mainthread continues after WaitForSingleObject, and still finds the "working" flag set.