I used these to protect a not-optimized-at-all dispatch queue built on top of std::deque (single reader, single writer, reader busy-waits until work is available, work is an empty function). I did this test on Mac OS X 10.6.8 (with Apple
s gcc 4.2.1 build).
Here are two really simple mutexes: a wrapper around the pthread functions, and a no-thought-required spinlock:
I used these to protect a not-optimized-at-all dispatch queue built on top of std::deque (single reader, single writer, reader busy-waits until work is available, work is an empty function). I did this test on Mac OS X 10.6.8 (with Apple s gcc 4.2.1 build).A run using PthreadMutex:
Using Spinlock: All times are in microseconds to run 1,000,000 iterations of the test. Only time to enqueue is measured.I've seen similar results with a very similar test on FreeBSD, though I don't have a box to retest on at the moment.
I can only conclude it's not at all unreasonable for PostgreSQL to use its own spinlocks.