I wrote a little program to test the speed of mutex and semaphore
lock/unlock, and discovered something interesting: Solaris 2.5.1 (with
recommended patches) appears an order of magnitude faster than Solaris
2.5 (at least on Intel). On my 486 at home, running Solaris 2.5:
loop overhead = 0.053270
1000000 mutex locks/unlocks in 34.027299
1000000 shared mutex locks/unlocks in 38.714911
1000000 semaphore locks/unlocks in 232.684178
1000000 shared semaphore locks/unlocks in 83.801712
On a Pentium/90 at work, running Solaris 2.5.1:
loop overhead = 0.043601
1000000 mutex locks/unlocks in 0.678123
1000000 shared mutex locks/unlocks in 0.684707
1000000 semaphore locks/unlocks in 6.291752
1000000 shared semaphore locks/unlocks in 8.843948
I haven't had time to upgrade my home box, but I definitely want to
explore these results further. I've upgraded my SPARCs at work to
Solaris 2.5.1, so I wasn't able to test if SPARC shares the same
performance problem, but I'd guess that it does (at any rate, 2.5.1 on
SPARC is approximately as fast as 2.5.1 on Intel). While POSIX
semaphores are a bit slower than Solaris semaphores (the numbers I
quoted above are Solaris mutexes/semaphores), the same general results
regarding 2.5/2.5.1 hold for them as well.
Another disturbing observation: A semaphore with the "shared" option
(shareable between processes) should be, if anything, slower than a
semaphore without shared (and indeed, it is a bit slower under 2.5.1),
but under Solaris 2.5, the exact opposite is true! This sounds like a
bug to me.
Can anyone at Sun shed some light on these numbers? I don't think the
speed is a problem, but the semaphore numbers are worrying me that maybe
someone reversed a test for the shared flag, which would imply that
semaphores aren't safe to share across processes? I can post my test
program if that would help. Thanks in advance!
Cheers,
Jake