[#108552] [Ruby master Bug#18782] Race conditions in autoload when loading the same feature with multiple threads. — "ioquatix (Samuel Williams)" <noreply@...>
Issue #18782 has been reported by ioquatix (Samuel Williams).
11 messages
2022/05/14
[ruby-core:108591] [Ruby master Feature#18774] Add Queue#pop(timeout:)
From:
"ioquatix (Samuel Williams)" <noreply@...>
Date:
2022-05-17 12:21:38 UTC
List:
ruby-core #108591
Issue #18774 has been updated by ioquatix (Samuel Williams).
There are several methods which should adopt timeouts, including `SizedQueue#push` and probably `Queue#each`, along with essentially any other blocking operations (e.g. `Kernel#system`, `Process#wait` etc).
I'd like to suggest we try to agree on a general method signature for timeouts, e.g.
```
Queue#pop(timeout:, exception: true/false/class)
```
We can share this signature across all methods using a small C interface like this:
```clang
struct rb_timeout_handler {
VALUE timeout; // Qnil or timeout value.
VALUE klass; // Qnil -> return nil, Qtrue -> raise TimeoutError, or exception class -> raise that class
};
void rb_timeout_make_handler(VALUE kwargs, struct timeout_handler *);
VALUE rb_timeout_handler_invoke(struct timeout_handler *) // Used if a timeout occurs to generate a return value or raise an exception.
```
----------------------------------------
Feature #18774: Add Queue#pop(timeout:)
https://bugs.ruby-lang.org/issues/18774#change-97627
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
----------------------------------------
This has been mentioned many times but somehow was never added.
It is useful for many different use cases:
* Implementing Timeout#timeout without needing to create a Thread per call which is very inefficient (especially when the timeout is not hit): https://github.com/ruby/timeout/pull/14#issuecomment-1123380880
* @jeremyevans0 I would love a Queue#pop :timeout argument. It would simplify the mutex/condition variable approach currently used for Sequel's connection pool.
* @byroot Same. I wanted it so many times
* https://bugs.ruby-lang.org/issues/17363
* https://spin.atomicobject.com/2014/07/07/ruby-queue-pop-timeout/ + https://spin.atomicobject.com/2017/06/28/queue-pop-with-timeout-fixed/
* More in my email searches but this seems already plenty
I think it should be a keyword argument for clarity, and so there is no confusion with the existing optional argument `non_block=false`.
--
https://bugs.ruby-lang.org/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>