[zeromq-dev] spin lock versus mutex
Steven McCoy
steven.mccoy at miru.hk
Sat Mar 27 05:29:21 CET 2010
Hi Hi,
In mutex.hpp spin locks are being for Win32 but not for POSIX, you
might see a performance increase by changing POSIX to use spin locks
too, although more likely you should implement both a zmq::mutex_t and
zmq::spinlock_t and decide on a case by case basis which is the best
to use.
Spin locks on Win32:
EnterCriticalSection(), LeaveCriticalSection()
Spin locks on Posix:
pthread_spinlock_lock(), pthread_spinlock_unlock()
Mutexes on Win32:
WaitForSingleObject(), ReleaseMutex()
Mutexes on Posix:
pthread_mutex_lock(), pthread_mutex_unlock()
I also noticed when using Conditions Win32 needs a spin lock but posix
needs a mutex, however I only use them to implement a read-write lock
on XP whereby Vista+ have a Condition API.
I saw a performance increase in OpenPGM making the change, but some
locks also completely froze, I don't know if that means a pthread
memory barrier needs to be used at the same time as the critical
section is very small.
--
Steve-o
More information about the zeromq-dev
mailing list