jeudi 12 avril 2012

MultiCore -- CRITICAL_SECTION are damn fast !

When talking about multicore programming (or "threaded programming", if you prefer), one of the first things that comes to mind is "mutex", "semaphore", and such.
In other words, synchronization primitives.

I won't go into much details or explanations here. I will rather assume you have a decent knowledge of all that.

As I was working on my TaskManager, hoping to make it lockfree, I was really surprised at how efficient the CRITICAL_SECTION can be.

After watching a video conf from Intel where they claimed how Microsoft new CONDITION_VARIABLE and SWRLOCK were super efficient, I ran a few benchmarks with various "safety" mechanisms, some locking while others lock-free.
The hardware was an Intel 4-core i7 with hyperthreading. So basically, 8 hardware threads.

Obviously CRITICAL_SECTION are a lot faster than (the aging) Windows Mutex mechanism.

But CRITICAL_SECTION were also :

  • faster than Windows SWRLOCK in exclusive mode
    -- this is surprising considering the MSDN docs, and those tests
  • faster than my custom SpinLock
    -- yeah sure that can depend on the kind of operations you are running concurrently... but still.

Even more surprising :
  • the pair {std::list<int>, CRITICAL_SECTION}, with search in the list, was even faster than my LockFreeQueue<T> with no search.

God donut !  >.<

I'll try to gather the data and present them properly here - in an update.
I wish I could run some tests on other hardware & OS.

Aucun commentaire:

Enregistrer un commentaire