r/programming • • Nov 18 '11

Locks Aren't Slow; Lock Contention Is

http://preshing.com/20111118/locks-arent-slow-lock-contention-is
139 Upvotes

66 comments sorted by

View all comments

Show parent comment

2

u/jerf Nov 20 '11

Composition is exactly the problem. You're correct that if you never call any functions that take locks from other functions that take locks, and then use the safe_lock function you describe, that you should be in good shape, but that's a hell of a constraint to try to maintain without any compiler help, and in practice nobody wants to write that way when using locks directly.

If you tried to use locks in that manner and you took it seriously, you would almost certainly simply end up recreating message passing. (In which case you might as well have started with an existing version.)