3 ms·
Looks nice. How is this implemented?
by nitely 9y ago
Looks nice. How is this implemented?
- rdtsc 9y agoNot 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/internet/defer.py#L1581 https://github.com/twisted/twisted/blob/trunk/src/twisted/in...