Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Not gp, but I used Twisted Matrix for a few years. It is usually implemented with a boolean flag and a list of client waiting to be called back when the lock is released.

So users of the lock would call acquire and get back a deferred (a promise in other language), but say in the most basic way, a callback is passed to it. When lock can be acquired, that callback is called (or deferred is fired).

When done with the resource, must call the release. Release then will trigger the lock to inspect the list of available waiting clients, pick one and fire their callback letting them know they can access the resource, and so on.

https://github.com/twisted/twisted/blob/trunk/src/twisted/in...



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: