[Openmcl-devel] Fine-grained locking
Daniel Herring
dherring at tentpost.com
Wed Mar 18 23:53:25 PDT 2009
On Tue, 17 Mar 2009, Ian Eslick wrote:
> Clozure is my performance target and I would like some input on the
> relative costs of two approaches to concurrency: fine-grained locking
> and copy-on-write.
I don't have the code/numbers handy, but I wrote a simple C test that
timed various synchronization techniques. If single async/plain memory
write had a cost of 1, then a single uncontested CAS had a cost of ~10 and
an uncontested pthread lock/unlock had a cost of ~100.
For many data structures, copy-on-write is a clear win since you don't
need to copy the data, just a pointer/reference.
As far as locking patterns go,
- If you have multiple locks, design a full ordering for their use so you
never have two threads lock them in different orders.
- Lock the smallest sections possible.
- Lock as few times as possible.
Later,
Daniel
More information about the Openmcl-devel
mailing list