What's new

How to efficiently use threads in your emulator?

blueshogun96

A lowdown dirty shame
Hey guys, I was wondering if some of you knew stuff about using threads. I've been trying to use threads in my emulator to simulate the emulation loop. Every time I use threads, they slow my emulator's performance to a crawl and kill my CPU usage. To be honest, I'm rather new at using threads, and is 4 threads too many? This sucks. Thanks.
 

zilmar

Emulator Developer
Moderator
threads have a lot of overhead in starting/stoping .. so depend on how you want to use them .. if you want to use them for short periods, write a thread pool class that has threads created and are just paused, pass them tasks to do.

I found tho it is hard to really make use of threads in emulation cause if you care about the timing of things then you need to make sure things sync correctly, the over head in making sure everything syncs can be higher then the time you save executing in another thread.

Threads will be come more important on dual/quad core cpus .. on single CPUs they will be a lot worse.
 
OP
blueshogun96

blueshogun96

A lowdown dirty shame
Ok, well, I don't have a dual/quad core CPU, so would there be a big performance hit if I just used one thread instead of the standard loop like in a game (which takes my CPU usage up to 100%)?
 

zilmar

Emulator Developer
Moderator
things that respond to the mouse and user input is good to be in there own thread. Anything that is asleep 99% of the time, but needs to act quickly when you get a response from hardware is good for a thread.

In a single CPU environment two threads running full ball is going to be worse then one thread just running. In a dual core environment tho, each one can have its own cpu and you will see a good speed increase.
 

Doomulation

?????????????????????????
Typically, you would want your GUI on one thread and emulation on one (or more). That will make sure your GUI is always responsive no matter what the emulation is doing.
Though I would image threads would be a nightmare if used in such things as the core. Threads will be very useful when doing lengthy and costly operations. Otherwise you would need to split work between threads, and to make them synchronized, which zilmar already stated, has a costly overhead.
 

smcd

Active member
As an example, MAME has only recently begun to consider multi core aspects (113u2 contains the first multi core aware driver)
 

Top