2 ms·
How often do you do something like that? Seems pretty rare. If you're managing locks maybe having an actual collection for them makes sense. If I had to choose
by boardwaalk 5y ago
How often do you do something like that? Seems pretty rare. If you're managing locks maybe having an actual collection for them makes sense.
If I had to choose between allowing that pattern and allowing reasonable usage in all control constructs, I'd choose the latter.
- Someone 5y agoI can see one use that when using lock ordering to prevent deadlocks (http://tutorials.jenkov.com/java-concurrency/deadlock-prevention.html#ordering http://tutorials.jenkov.com/java-concurrency/deadlock-preven...), but then, the locks to be taken are a fixed set, and one probably would have function take_locks(lock *) and release_locks(lock *), and one could do defer release_locks. Also, Wikipedia (https://en.wikipedia.org/wiki/Deadlock https://en.wikipedia.org/wiki/Deadlock, https://en.wikipedia.org/wiki/Deadlock_prevention_algorithms https://en.wikipedia.org/wiki/Deadlock_prevention_algorithms) doesn’t seem to know about it. Even though I expect/guess it to be popular in embedded work, that makes me wonder whether lock ordering is used much. Could also be an omission in Wikipedia. It has https://en.wikipedia.org/wiki/Banker%27s_algorithm https://en.wikipedia.org/wiki/Banker%27s_algorithm, which I hadn’t heard of, and that Wikipedia says of “In most systems, this information is unavailable, making it impossible to implement the Banker's algorithm. Also, it is unrealistic to assume that the number of processes is static since in most systems the number of processes varies dynamically”