logoalt Hacker News

expedetoday at 12:50 AM0 repliesview on HN

(Author here) it depends on your use case. If you need to incrementally acquire locks, then levels are helpful. A place where this comes up is if you need to read a value out of one lock, and need to pick what to lock next based on that without releasing the first one. Of course you should think twice when doing this but when you need it, you REALLY need it.

Opting out of lock levels was a design goal. By default all locks are are level 1, and get even the level can be omitted thanks to a default type parameter. Levels have no runtime cost, so sidestepping them is free. This lets you live in a atomic-locks only world, and if you later find that you need incremental locks later, you can add more levels then :)