mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* eval.c (rb_thread_select): should subtract timeofday() from
limit, not reverse. * util.c (scan_hex): x is not a hexadecimal digit. * eval.c (rb_thread_schedule): should treat the case that select(2) returns 0, if a thread is under both WAIT_SELECT and WAIT_TIME. Jakub Travnik <J.Travnik@sh.cvut.cz> actually fixed this bug. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@1862 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
186c8b592a
commit
6ab0ff977d
6 changed files with 89 additions and 54 deletions
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
||||||
|
Wed Nov 28 18:46:28 2001 Ville Mattila <mulperi@iki.fi>
|
||||||
|
|
||||||
|
* eval.c (rb_thread_select): should subtract timeofday() from
|
||||||
|
limit, not reverse.
|
||||||
|
|
||||||
|
Wed Nov 28 16:03:28 2001 K.Kosako <kosako@sofnec.co.jp>
|
||||||
|
|
||||||
|
* util.c (scan_hex): x is not a hexadecimal digit.
|
||||||
|
|
||||||
|
Wed Nov 28 13:38:04 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* eval.c (rb_thread_schedule): should treat the case that
|
||||||
|
select(2) returns 0, if a thread is under both WAIT_SELECT and
|
||||||
|
WAIT_TIME. Jakub Travnik <J.Travnik@sh.cvut.cz> actually fixed
|
||||||
|
this bug.
|
||||||
|
|
||||||
Tue Nov 27 02:15:25 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Tue Nov 27 02:15:25 2001 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* marshal.c (w_float): must distinguish -0.0 from 0.0.
|
* marshal.c (w_float): must distinguish -0.0 from 0.0.
|
||||||
|
|
24
eval.c
24
eval.c
|
@ -7571,6 +7571,7 @@ rb_thread_schedule()
|
||||||
double delay, now; /* OK */
|
double delay, now; /* OK */
|
||||||
int n, max;
|
int n, max;
|
||||||
int need_select = 0;
|
int need_select = 0;
|
||||||
|
int select_timeout = 0;
|
||||||
|
|
||||||
rb_thread_pending = 0;
|
rb_thread_pending = 0;
|
||||||
if (curr_thread == curr_thread->next
|
if (curr_thread == curr_thread->next
|
||||||
|
@ -7615,7 +7616,7 @@ rb_thread_schedule()
|
||||||
if (max < th->fd) max = th->fd;
|
if (max < th->fd) max = th->fd;
|
||||||
need_select = 1;
|
need_select = 1;
|
||||||
if (th->wait_for & WAIT_TIME) {
|
if (th->wait_for & WAIT_TIME) {
|
||||||
need_select = 2;
|
select_timeout = 1;
|
||||||
}
|
}
|
||||||
th->select_value = 0;
|
th->select_value = 0;
|
||||||
}
|
}
|
||||||
|
@ -7676,14 +7677,17 @@ rb_thread_schedule()
|
||||||
}
|
}
|
||||||
END_FOREACH_FROM(curr, th);
|
END_FOREACH_FROM(curr, th);
|
||||||
}
|
}
|
||||||
if (n == 0 && need_select == 2) {
|
if (select_timeout && n == 0) {
|
||||||
if (now < 0.0) now = timeofday();
|
if (now < 0.0) now = timeofday();
|
||||||
FOREACH_THREAD_FROM(curr, th) {
|
FOREACH_THREAD_FROM(curr, th) {
|
||||||
if ((th->wait_for & (WAIT_SELECT|WAIT_TIME)) && th->delay < now) {
|
if ((th->wait_for & (WAIT_SELECT|WAIT_TIME)) && th->delay < now) {
|
||||||
th->status = THREAD_RUNNABLE;
|
th->status = THREAD_RUNNABLE;
|
||||||
th->wait_for = 0;
|
th->wait_for = 0;
|
||||||
th->select_value = 0;
|
th->select_value = 0;
|
||||||
found = 1;
|
found = 1;
|
||||||
|
intersect_fds(&readfds, &th->readfds, max);
|
||||||
|
intersect_fds(&writefds, &th->writefds, max);
|
||||||
|
intersect_fds(&exceptfds, &th->exceptfds, max);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
END_FOREACH_FROM(curr, th);
|
END_FOREACH_FROM(curr, th);
|
||||||
|
@ -7912,7 +7916,7 @@ rb_thread_select(max, read, write, except, timeout)
|
||||||
case ERESTART:
|
case ERESTART:
|
||||||
#endif
|
#endif
|
||||||
if (timeout) {
|
if (timeout) {
|
||||||
double d = timeofday() - limit;
|
double d = limit - timeofday();
|
||||||
|
|
||||||
tv.tv_sec = (unsigned int)d;
|
tv.tv_sec = (unsigned int)d;
|
||||||
tv.tv_usec = (long)((d-(double)tv.tv_sec)*1e6);
|
tv.tv_usec = (long)((d-(double)tv.tv_sec)*1e6);
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# This achieved by marking
|
# This achieved by marking
|
||||||
# * Klass.new and Klass.allocate - as private and
|
# * Klass.new and Klass.allocate - as private and modifying
|
||||||
# * Klass.inherited(sub_klass) - modifying to ensure
|
# * Klass.inherited(sub_klass) - to ensure
|
||||||
# that the Singleton pattern is properly inherited.
|
# that the Singleton pattern is properly inherited.
|
||||||
#
|
#
|
||||||
# In addition Klass is provided with the class methods
|
# In addition Klass is provided with the class methods
|
||||||
|
@ -39,7 +39,7 @@
|
||||||
# The sole instance method of Singleton is
|
# The sole instance method of Singleton is
|
||||||
# * _dump(depth) - returning the empty string
|
# * _dump(depth) - returning the empty string
|
||||||
# The default Marshalling strategy is to strip all state information - i.e.
|
# The default Marshalling strategy is to strip all state information - i.e.
|
||||||
# instance variables from ``the instance''. Providing costume
|
# instance variables from ``the instance''. Providing custom
|
||||||
# _dump(depth) and _load(str) method allows the (partial) resurrection
|
# _dump(depth) and _load(str) method allows the (partial) resurrection
|
||||||
# of a previous state of ``the instance'' - see third example.
|
# of a previous state of ``the instance'' - see third example.
|
||||||
#
|
#
|
||||||
|
@ -53,12 +53,12 @@ module Singleton
|
||||||
# * nil - before (and after a failed) creation
|
# * nil - before (and after a failed) creation
|
||||||
# * false - during creation
|
# * false - during creation
|
||||||
# * sub_class instance - after a successful creation
|
# * sub_class instance - after a successful creation
|
||||||
@__instance__ = nil
|
sub_klass.instance_eval { @__instance__ = nil }
|
||||||
def sub_klass.instance
|
def sub_klass.instance
|
||||||
unless @__instance__.nil?
|
unless @__instance__.nil?
|
||||||
# is the extra flexiblity having the hook method
|
# is the extra flexiblity having the hook method
|
||||||
# _wait() around ever useful?
|
# _wait() around ever useful?
|
||||||
_wait() while false.equal?(@__instance__)
|
_wait()
|
||||||
# check for instance creation
|
# check for instance creation
|
||||||
return @__instance__ if @__instance__
|
return @__instance__ if @__instance__
|
||||||
end
|
end
|
||||||
|
@ -86,7 +86,7 @@ module Singleton
|
||||||
instance
|
instance
|
||||||
end
|
end
|
||||||
def _wait
|
def _wait
|
||||||
sleep(0.05)
|
sleep(0.05) while false.equal?(@__instance__)
|
||||||
end
|
end
|
||||||
private :new, :allocate
|
private :new, :allocate
|
||||||
# hook methods are also marked private
|
# hook methods are also marked private
|
||||||
|
@ -115,55 +115,63 @@ rescue NoMethodError => mes
|
||||||
puts mes
|
puts mes
|
||||||
end
|
end
|
||||||
|
|
||||||
# threaded example with exception
|
# threaded example with exception and customized hook #_wait method
|
||||||
Thread.abort_on_exception = true
|
Thread.abort_on_exception = false
|
||||||
class Ups < SomeSingletonClass
|
def num_of_instances(mod)
|
||||||
@__threads__= []
|
"#{ObjectSpace.each_object(mod){}} #{mod} instance"
|
||||||
@__flip__ = nil
|
end
|
||||||
@@__index__ = nil
|
|
||||||
|
|
||||||
|
class Ups < SomeSingletonClass
|
||||||
def initialize
|
def initialize
|
||||||
sleep(rand(0.1)/10.0)
|
type.__sleep
|
||||||
Thread.current[:index] = @@__index__
|
puts "initialize called by thread ##{Thread.current[:i]}"
|
||||||
end
|
end
|
||||||
class << self
|
class << self
|
||||||
|
def _wait
|
||||||
|
@enter.push Thread.current[:i]
|
||||||
|
sleep 0.02 while false.equal?(@__instance__)
|
||||||
|
@leave.push Thread.current[:i]
|
||||||
|
end
|
||||||
|
def __sleep
|
||||||
|
sleep (rand(0.1))
|
||||||
|
end
|
||||||
def allocate
|
def allocate
|
||||||
unless @__flip__
|
__sleep
|
||||||
@__flip__ = true
|
def self.allocate; __sleep; super() end
|
||||||
raise "boom - allocation in thread ##{@@__index__} aborted"
|
raise "allocation in thread ##{Thread.current[:i]} aborted"
|
||||||
end
|
|
||||||
super()
|
|
||||||
end
|
end
|
||||||
def instanciate_all
|
def instanciate_all
|
||||||
1.upto(5) do |@@__index__|
|
@enter = []
|
||||||
sleep(rand(0.1)/10.0)
|
@leave = []
|
||||||
@__threads__.push Thread.new {
|
1.upto(9) do |i|
|
||||||
begin
|
Thread.new do
|
||||||
instance
|
begin
|
||||||
rescue RuntimeError => mes
|
Thread.current[:i] = i
|
||||||
puts mes
|
__sleep
|
||||||
end
|
instance
|
||||||
}
|
rescue RuntimeError => mes
|
||||||
|
puts mes
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
def join
|
puts "Before there were #{num_of_instances(Ups)}s"
|
||||||
@__threads__.each do |t|
|
sleep 3
|
||||||
t.join
|
puts "Now there is #{num_of_instances(Ups)}"
|
||||||
puts "initialize called by thread ##{t[:index]}" if
|
puts "#{@enter.join "; "} was the order of threads entering the waiting loop"
|
||||||
t[:index]
|
puts "#{@leave.join "; "} was the order of threads leaving the waiting loop"
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
puts "There is(are) #{ObjectSpace.each_object(Ups) {}} Ups instance(s)"
|
|
||||||
# => The is(are) 0 Ups instance(s)
|
|
||||||
Ups.instanciate_all
|
Ups.instanciate_all
|
||||||
Ups.join # => initialize called by thread # i - where i = 2 ... 5
|
# results in message like
|
||||||
p Marshal.load(Marshal.dump(Ups.instance)) == Ups.instance # => true
|
# Before there were 0 Ups instances
|
||||||
puts "There is(are) #{ObjectSpace.each_object(Ups) {}} Ups instance(s)"
|
# boom - allocation in thread #8 aborted
|
||||||
# => The is(are) 1 Ups instance(s)
|
# initialize called by thread #3
|
||||||
|
# Now there is 1 Ups instance
|
||||||
|
# 2; 3; 6; 1; 7; 5; 9; 4 was the order of threads entering the waiting loop
|
||||||
|
# 3; 2; 1; 7; 6; 5; 4; 9 was the order of threads leaving the waiting loop
|
||||||
|
|
||||||
|
|
||||||
# Customized marshalling
|
# Customized marshalling
|
||||||
class A
|
class A
|
||||||
|
|
|
@ -522,7 +522,14 @@ The variable ruby-indent-level controls the amount of indentation.
|
||||||
(re-search-backward "#" (save-excursion
|
(re-search-backward "#" (save-excursion
|
||||||
(beginning-of-line)
|
(beginning-of-line)
|
||||||
(point)) t)
|
(point)) t)
|
||||||
|
(save-excursion
|
||||||
|
(forward-char -1)
|
||||||
|
(not (looking-at "\\?")))
|
||||||
(skip-chars-backward " \t")
|
(skip-chars-backward " \t")
|
||||||
|
(if (save-excursion
|
||||||
|
(forward-char -1)
|
||||||
|
(looking-at "\\?"))
|
||||||
|
(skip-chars-forward " \t"))
|
||||||
(setq state (ruby-parse-region parse-start (point)))
|
(setq state (ruby-parse-region parse-start (point)))
|
||||||
(nth 0 state)
|
(nth 0 state)
|
||||||
(goto-char pos)))
|
(goto-char pos)))
|
||||||
|
|
2
util.c
2
util.c
|
@ -47,7 +47,7 @@ const char *start;
|
||||||
int len;
|
int len;
|
||||||
int *retlen;
|
int *retlen;
|
||||||
{
|
{
|
||||||
static char hexdigit[] = "0123456789abcdef0123456789ABCDEFx";
|
static char hexdigit[] = "0123456789abcdef0123456789ABCDEF";
|
||||||
register const char *s = start;
|
register const char *s = start;
|
||||||
register unsigned long retval = 0;
|
register unsigned long retval = 0;
|
||||||
char *tmp;
|
char *tmp;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
#define RUBY_VERSION "1.7.2"
|
#define RUBY_VERSION "1.7.2"
|
||||||
#define RUBY_RELEASE_DATE "2001-11-25"
|
#define RUBY_RELEASE_DATE "2001-11-28"
|
||||||
#define RUBY_VERSION_CODE 172
|
#define RUBY_VERSION_CODE 172
|
||||||
#define RUBY_RELEASE_CODE 20011125
|
#define RUBY_RELEASE_CODE 20011128
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue