[ruby-core:124508] [Ruby Feature#21821] Add Stack and SizedStack classes
Issue #21821 has been updated by Eregon (Benoit Daloze). From a quick look the closest thing to a concurrent Stack in Java is [LinkedBlockingDeque](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concu...). That implementation uses a single lock and condition variables, so it's not particularly efficient and likely causes significant contention. In comparison [LinkedBlockingQueue](https://docs.oracle.com/en/java/javase/25/docs/api/java.base/java/util/concu...) uses two locks (basically one for push, one for pop) to avoid contention, unless the queue is completely empty and then both locks need to be taken. That illustrates my point that having a `Deque` limits the implementation choices and optimizations significantly. ---------------------------------------- Feature #21821: Add Stack and SizedStack classes https://bugs.ruby-lang.org/issues/21821#change-116068 * Author: byroot (Jean Boussier) * Status: Open * Target version: 4.1 ---------------------------------------- ### Context `Queue` and `SizedQueue` are very useful and performant constructs, however they only allow for FIFO queues. Some use cases do call for LIFO queues AKA stacks. For instance, in the case of connection pool, it's often preferable to use a stack. ### Feature I'd like to introduce `Stack` and `SizedStack` classes, to mirror `Queue` and `SizedQueue`. They'd have exactly the same method and behavior at the exception of dequeuing order. ### Thread namespace? Currently `Queue` and `SizedQueue` are technically defined under `Thread` and aliased in `Object`. I wonder if that's something we should do for `Stack` too, or just some historical thing we shouldn't perpetuate. -- https://bugs.ruby-lang.org/
participants (1)
-
Eregon (Benoit Daloze)