So I've been adding in some multi threading to my game demo. It all works fine until I create more threads than I have cores on my CPU.
I've only got a dual core so I have the main thread and an extra helper thread, if for whatever reason I create a third thread then performance drops considerably - like going from a super car to your dad's first Ford.
With a single thread I get 50 fps, with two threads I get 70 fps but with three threads I get 8 fps.
Using Very Sleepy to see what's going on; when I add the third thread a lot of time is spent in
ReleaseSemaphore, but there is only one place I use that and the locks are going to get called the same number of times regardless of the number of threads because there's only a limited amount of data.
I create the threads at startup using
CreateThread and they then wait for en event to signal that there is work for them to do, once the work is done they'll be waiting for the event again.
I've not done much threading so am I doing something immensely stupid that's causing the horrific performance?