OpenImageIO/oiio — pull request #747 by gchatelet (2013-11-24 18:44:42+00:00)
Title: C++11 implementation for thread.h

A proposal to use C++11 atomics when available.

Some before/after comparisons on my quad-core machine (Arch Linux x86-64).
Compiler used : Clang 3.3 and GCC 4.8.2

More tests need to be done especially for other platforms and many processors motherboards.

```
atomic_test --threads 12 --trials 2 --wedge;
Clang GCC Clang GCC
threads baseline baseline C++11 C++11
1 3.9 3.9 3.9 3.9
2 13.2 13.5 13 13.2
4 14.7 14.9 14.6 14.4
8 14.7 14.7 14.8 14.7
12 14.8 15 14.8 14.5
```
No noticeable impact for atomics.

```
spinlock_test --threads 12 --trials 10 --wedge;
Clang GCC Clang GCC
threads baseline baseline C++11 C++11
1 0.5 0.5 0.6 0.6
2 0.7 0.7 0.7 0.7
4 1.1 1.4 1.4 1.5
8 1.4 1.4 1.7 1.8
12 1.4 1.3 1.7 1.7
```
Spinlock seems to be a bit slower under high contention (here hw_threads=4), I'm not sure I can make it as fast as the original within defined behaviour. Also a benchmark on a better machine would make much more sense.

```
spin_rw_test --threads 12 --trials 5 --wedge --rwratio 99
Clang GCC Clang GCC
threads baseline baseline C++11 C++11
1 0.6 0.8 0.6 0.8
2 1.5 1.5 0.7 1.4
4 3 3.9 3.1 3.5
8 3.3 3.1 2.8 3.2
12 3.3 2.9 2.7 3
```
Clang with C++11 implementation seems to be consistently the fastest in this test, and GCC seems to be slower overall.

This patch also fixes a few other issues triggered by this proposal.

GCC with c++11 seems to trigger new warnings (had to add `-Wno-unused-local-typedefs` and deactivate warning as errors)