Queue and timeout

timeout e$B$Ge(B Queue#pop e$B$K;[email protected])8B$r$D$1$?;~!"%?%$%`%"%&%H;~$Ke(B
Timeout::Error e$B$G$J$/e(B ThreadError e$B$,H/@8$7$^$9!#e(B

% ./ruby -v -rtimeout -rthread -e ’
q = Queue.new
timeout(1) { q.pop }

ruby 1.9.0 (2008-01-06 revision 0) [i686-linux]
prelude.rb:10:in unlock': Attempt to unlock a mutex which is locked by another thread (ThreadError) from prelude.rb:10:inensure in synchronize’
from prelude.rb:10:in synchronize' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/thread.rb:181:inpop’
from -e:3:in block in <main>' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/timeout.rb:46:intimeout’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/timeout.rb:65:in
timeout' from -e:3:in
zsh: exit 1 ./ruby -v -rtimeout -rthread -e ’ q = Queue.new
timeout(1) { q.pop } ’

1.8 e$B$G$Oe(B Timeout::Error e$B$G$7$?!#e(B

% ruby-1.8 -v -rtimeout -rthread -e ’
q = Queue.new
timeout(1) { q.pop }

ruby 1.8.6 (2007-12-14 patchlevel 5000) [i686-linux]
/home/akr/ruby/18/lib/ruby/1.8/timeout.rb:54: execution expired
(Timeout::Error)
from /home/akr/ruby/18/lib/ruby/1.8/timeout.rb:56:in timeout' from /home/akr/ruby/18/lib/ruby/1.8/timeout.rb:76:intimeout’
from -e:3

e$B$*$=$i$/$3$l$N$;$$$G!"e(Bresolv e$B$,$&$^$/F0$-$^$;$s!#e(B

% ./ruby -v -rresolv -e ’
ts = (1…10).map { Thread.new { p Resolv.getaddress(“www.rubyist.net”) }
}
ts.each {|t| t.join }

ruby 1.9.0 (2008-01-06 revision 0) [i686-linux]
“221.186.184.67”
“221.186.184.67”
“221.186.184.67”
prelude.rb:10:in unlock': Attempt to unlock a mutex which is locked by another thread (ThreadError) from prelude.rb:10:inensure in synchronize’
from prelude.rb:10:in synchronize' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/thread.rb:181:inpop’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:495:in
block (2 levels) in each_resource' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/timeout.rb:46:intimeout’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/timeout.rb:65:in
timeout' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:495:inblock in each_resource’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:891:in
block (3 levels) in resolv' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:889:ineach’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:889:in
block (2 levels) in resolv' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:888:ineach’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:888:in
block in resolv' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:886:ineach’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:886:in
resolv' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:485:ineach_resource’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:390:in
each_address' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:110:inblock in each_address’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:109:in
each' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:109:ineach_address’
from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:87:in
getaddress' from /home/akr/ruby/yarvo0/lib/ruby/1.9.0/resolv.rb:38:ingetaddress’
from -e:2:in `block (2 levels) in ’

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:32935] queue and timeout”
on Sun, 6 Jan 2008 19:22:19 +0900, Tanaka A. [email protected]
writes:

|timeout e$B$Ge(B Queue#pop e$B$K;[email protected])8B$r$D$1$?;~!"%?%$%`%"%&%H;~$Ke(B
|Timeout::Error e$B$G$J$/e(B ThreadError e$B$,H/@8$7$^$9!#e(B

e$BDI$$$+$1$F$_$^$7$?!#e(B

Queue#pope$B$,e(BMutex#synchronizee$B$N%V%m%C%/Cf$Ge(BMutex#sleepe$B$r8F$Ve(B

  • Mutex#sleepe$B$,e(Brb_mutex_unlock()e$B$r8F$Ve(B
  • e$B$3$3$Ge(BTimeout

Mutex#synchronizee$B$,CfCG!#e(Bensuree$B$Ge(BMutex#unlocke$B$,8F$P$l$ke(B

  • e$B$9$G$Ke(Bunlocke$B$5$l$F$$$k$N$Ge(BThreadErrore$BNc30e(B
  • Timeout::Errore$BNc30$OL5;k$5$l$A$c$&e(B

e$B$H$$$&N.$l$N$h$&$G$9!#$A$g$C$H9M$($k$He(B

  • Mutex#sleepe$B$Oe(Bmutex->the$B$r%/%j%"$7$J$$e(B
  • Mutex#unlocke$B$Oe(Bmutex->th==0e$B$N;~Nc30$r5/$3$5$J$$e(B

e$B$J$I$NBP1~$,9M$($i$l$^$9$,!"I{:nMQ$,5$$K$J$j$^$9!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

[email protected]>;3OB9-$G$9!#e(B

At Thu, 10 Jan 2008 02:51:11 +0900,
Yukihiro M. wrote:

e$B$H$$$&N.$l$N$h$&$G$9!#$A$g$C$H9M$($k$He(B

  • Mutex#sleepe$B$Oe(Bmutex->the$B$r%/%j%"$7$J$$e(B
  • Mutex#unlocke$B$Oe(Bmutex->th==0e$B$N;~Nc30$r5/$3$5$J$$e(B

e$B$J$I$NBP1~$,9M$($i$l$^$9$,!"I{:nMQ$,5$$K$J$j$^$9!#e(B

e$BF1$8$/$A$g$C$H9M$([email protected]$1$G$9$,!"e(BMutex#sleepe$B$Ge(BMutexe$B$r2rJ|$7$J$$$He(B
Queue#pushe$B$,$G$-$J$$$N$G$O$J$$$G$7$g$&$+e(B?

Mutex#unlocke$B$NJQ$o$j$KNc30$r5/$3$5$J$$e(BMutex#try_unlocke$B$rDI2C$7$Fe(B
e$B;H$&$H$$$&$N$O$I$&$G$7$g$&$+e(B?

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:33004] Re: queue and timeout”
on Thu, 10 Jan 2008 17:44:13 +0900, Kazuhiro NISHIYAMA
[email protected] writes:

|> * Queue#pope$B$,e(BMutex#synchronizee$B$N%V%m%C%/Cf$Ge(BMutex#sleepe$B$r8F$Ve(B
|> * Mutex#sleepe$B$,e(Brb_mutex_unlock()e$B$r8F$Ve(B
|> * e$B$3$3$Ge(BTimeout
|> * Mutex#synchronizee$B$,CfCG!#e(Bensuree$B$Ge(BMutex#unlocke$B$,8F$P$l$ke(B
|> * e$B$9$G$Ke(Bunlocke$B$5$l$F$$$k$N$Ge(BThreadErrore$BNc30e(B
|> * Timeout::Errore$BNc30$OL5;k$5$l$A$c$&e(B
|>
|> e$B$H$$$&N.$l$N$h$&$G$9!#$A$g$C$H9M$($k$He(B
|>
|> * Mutex#sleepe$B$Oe(Bmutex->the$B$r%/%j%"$7$J$$e(B
|> * Mutex#unlocke$B$Oe(Bmutex->th==0e$B$N;~Nc30$r5/$3$5$J$$e(B
|>
|> e$B$J$I$NBP1~$,9M$($i$l$^$9$,!"I{:nMQ$,5$$K$J$j$^$9!#e(B
|
|e$BF1$8$/$A$g$C$H9M$([email protected]$1$G$9$,!"e(BMutex#sleepe$B$Ge(BMutexe$B$r2rJ|$7$J$$$He(B
|Queue#pushe$B$,$G$-$J$$$N$G$O$J$$$G$7$g$&$+e(B?

e$B$$$d!"e(BMutex#sleepe$B$Ge(BMutexe$B$O2rJ|$9$k$s$G$9$h!#[email protected]!“e(Bmutex->th
e$B$re(B0e$B%/%j%”$7$J$$$H$$$&[email protected]$1$G!#e(B

|Mutex#unlocke$B$NJQ$o$j$KNc30$r5/$3$5$J$$e(BMutex#try_unlocke$B$rDI2C$7$Fe(B
|e$B;H$&$H$$$&$N$O$I$&$G$7$g$&$+e(B?

e$B$=$C$A$,$$$$$N$+$J$"!#$"$k$$$Oe(B unlock e$B$Ke(B rescue
e$B$rIU$1$A$c$&e(B
e$B$+!#[email protected]!"JBNs%W%m%0%i%_%s%0AG?M$N;d$,<j$r=P$9$H$d$1$I$7$A$ce(B
e$B$$$=$&!#e(B

In article [email protected],
Nobuyoshi N. [email protected] writes:

e$BK\Mh%(%i!<$K$J$k$Y$-$H$3$m$,$o$+$i$J$/$J$k$N$,LdBj$+$b$H;W$$$^$7e(B
e$B$?$,!"e(BIO#opene$B$J$s$+$bF1$8$3$H$J$N$G$$$$$s$8$c$J$$$G$7$g$&$+!#e(B-d
e$B%*%W%7%g%s$D$-$N$H$-$K$&$k$5$/$J$$$H$$$&[email protected]$G$O!"e(Btry_unlocke$B$N$[$&e(B
e$B$,$$$$$+$b$7$l$^$;$s$,!#e(B

e$B$=$l$O$=$l$H$7$F$b$C$H:,K\E*$K$O!"e(Btimeout e$B$D$-$Ne(B pop
e$B$rDI2Ce(B
e$B$9$k$N$,$$$$$h$&$J5$$,$7$^$9!#e(B

[email protected]$G$9!#e(B

At Thu, 10 Jan 2008 17:54:47 +0900,
Yukihiro M. wrote in [ruby-dev:33005]:

|e$BF1$8$/$A$g$C$H9M$([email protected]$1$G$9$,!"e(BMutex#sleepe$B$Ge(BMutexe$B$r2rJ|$7$J$$$He(B
|Queue#pushe$B$,$G$-$J$$$N$G$O$J$$$G$7$g$&$+e(B?

e$B$$$d!"e(BMutex#sleepe$B$Ge(BMutexe$B$O2rJ|$9$k$s$G$9$h!#[email protected]!“e(Bmutex->th
e$B$re(B0e$B%/%j%”$7$J$$$H$$$&[email protected]$1$G!#e(B

e$B$$$d!“e(Bmutex->the$B$re(B0e$B%/%j%”$9$k$3$H$Ge(BMutexe$B$,2rJ|$5$l$?$3$H$K$J$k$Ne(B
e$B$G$O!#e(B

|Mutex#unlocke$B$NJQ$o$j$KNc30$r5/$3$5$J$$e(BMutex#try_unlocke$B$rDI2C$7$Fe(B
|e$B;H$&$H$$$&$N$O$I$&$G$7$g$&$+e(B?

e$B$=$C$A$,$$$$$N$+$J$"!#$"$k$$$Oe(B unlock e$B$Ke(B rescue e$B$rIU$1$A$c$&e(B
e$B$+!#[email protected]!"JBNs%W%m%0%i%_%s%0AG?M$N;d$,<j$r=P$9$H$d$1$I$7$A$ce(B
e$B$$$=$&!#e(B

e$BK\Mh%(%i!<$K$J$k$Y$-$H$3$m$,$o$+$i$J$/$J$k$N$,LdBj$+$b$H;W$$$^$7e(B
e$B$?$,!"e(BIO#opene$B$J$s$+$bF1$8$3$H$J$N$G$$$$$s$8$c$J$$$G$7$g$&$+!#e(B-d
e$B%*%W%7%g%s$D$-$N$H$-$K$&$k$5$/$J$$$H$$$&[email protected]$G$O!"e(Btry_unlocke$B$N$[$&e(B
e$B$,$$$$$+$b$7$l$^$;$s$,!#e(B

[email protected]$G$9!#e(B

At Thu, 10 Jan 2008 19:47:26 +0900,
Yukihiro M. wrote in [ruby-dev:33008]:

|> e$B$$$d!"e(BMutex#sleepe$B$Ge(BMutexe$B$O2rJ|$9$k$s$G$9$h!#[email protected]!“e(Bmutex->th
|> e$B$re(B0e$B%/%j%”$7$J$$$H$$$&[email protected]$1$G!#e(B
|
|e$B$$$d!“e(Bmutex->the$B$re(B0e$B%/%j%”$9$k$3$H$Ge(BMutexe$B$,2rJ|$5$l$?$3$H$K$J$k$Ne(B
|e$B$G$O!#e(B

e$B$$$^$$$Ae(B pthread e$B%W%m%0%i%_%s%0$K47$l$F$$$J$$$s$G$9$,!“e(B
mutex->th e$B$,%/%j%”$5$l$F$J$/$F$b!"e(Bnative_mutex_unlock()e$B$,8Fe(B
e$B$P$l$l$P2rJ|$5$l$?$3$H$K$J$k$s$G$O$J$$$+$H!#e(B

pthread_mutex_te$B$Oe(Bcancelablee$B$G$J$$$N$G!“e(BMutexe$B$G$OD>@;H$C$F$O$$$^e(B
e$B$;$s!#e(Brb_mutex_unlock()e$B$G%m%C%/e(B/e$B%”%s%m%C%/$7$F$$$k$N$O!"e(Bmutex_t
e$B<+BN$KBP$9$kGSB>@)[email protected]$1$G$9!#e(B

e$B1sF#$H?=$7$^$9!#e(B

e$B$=$b$=$bC/$b%m%C%/$7$F$J$$e(B Mutex e$B$re(B unlock
e$B$7$h$&$H$7$?$H$-$Ke(B
Attempt to unlock a mutex which is locked by another thread
[email protected]$G$O$J$$$G$7$g$&$+!#CN$i$J$$$H$O$^$j$=$&$G$9!#e(B

Index: thread.c

— thread.c (revision 14978)
+++ thread.c (working copy)
@@ -2362,22 +2362,30 @@
rb_mutex_unlock(VALUE self)
{
mutex_t *mutex;

  • char *err = NULL;
    GetMutexPtr(self, mutex);
  • if (mutex->th != GET_THREAD()) {
  • rb_raise(rb_eThreadError,
  • "Attempt to unlock a mutex which is locked by another thread");
    
  • native_mutex_lock(&mutex->lock);
  • if (mutex->th == 0) {
  • err = “Attempt to unlock a mutex which is not locked”;
    }
  • else if (mutex->th != GET_THREAD()) {
  • err = “Attempt to unlock a mutex which is locked by another thread”;
  • }
  • else {
  • mutex->th = 0;
  • if (mutex->cond_waiting > 0) {
  •  /* waiting thread */
    
  •  native_cond_signal(&mutex->cond);
    
  •  mutex->cond_waiting--;
    
  • }
  • }
  • native_mutex_lock(&mutex->lock);
  • mutex->th = 0;
  • if (mutex->cond_waiting > 0) {
  • /* waiting thread */
  • native_cond_signal(&mutex->cond);
  • mutex->cond_waiting–;
  • }
    native_mutex_unlock(&mutex->lock);
  • if (err) rb_raise(rb_eThreadError, err);
  • return self;
    }

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:33006] Re: queue and timeout”
on Thu, 10 Jan 2008 19:35:48 +0900, Nobuyoshi N.
[email protected] writes:

|> e$B$$$d!"e(BMutex#sleepe$B$Ge(BMutexe$B$O2rJ|$9$k$s$G$9$h!#[email protected]!“e(Bmutex->th
|> e$B$re(B0e$B%/%j%”$7$J$$$H$$$&[email protected]$1$G!#e(B
|
|e$B$$$d!“e(Bmutex->the$B$re(B0e$B%/%j%”$9$k$3$H$Ge(BMutexe$B$,2rJ|$5$l$?$3$H$K$J$k$Ne(B
|e$B$G$O!#e(B

e$B$$$^$$$Ae(B pthread e$B%W%m%0%i%_%s%0$K47$l$F$$$J$$$s$G$9$,!“e(B
mutex->th e$B$,%/%j%”$5$l$F$J$/$F$b!"e(Bnative_mutex_unlock()e$B$,8Fe(B
e$B$P$l$l$P2rJ|$5$l$?$3$H$K$J$k$s$G$O$J$$$+$H!#e(B

|> e$B$=$C$A$,$$$$$N$+$J$"!#$"$k$$$Oe(B unlock e$B$Ke(B rescue e$B$rIU$1$A$c$&e(B
|> e$B$+!#[email protected]!"JBNs%W%m%0%i%_%s%0AG?M$N;d$,<j$r=P$9$H$d$1$I$7$A$ce(B
|> e$B$$$=$&!#e(B
|
|e$BK\Mh%(%i!<$K$J$k$Y$-$H$3$m$,$o$+$i$J$/$J$k$N$,LdBj$+$b$H;W$$$^$7e(B
|e$B$?$,!"e(BIO#opene$B$J$s$+$bF1$8$3$H$J$N$G$$$$$s$8$c$J$$$G$7$g$&$+!#e(B-d
|e$B%*%W%7%g%s$D$-$N$H$-$K$&$k$5$/$J$$$H$$$&[email protected]$G$O!"e(Btry_unlocke$B$N$[$&e(B
|e$B$,$$$$$+$b$7$l$^$;$s$,!#e(B

e$B$H$j$"$($:e(B rescue e$BIU$1$H$-$^$7$?!#ITK~$,$"$l$P!"[email protected]$/$se(B
(e$B!)e(B)e$B$,D>$7$F$/$l$k$G$7$g$&!#e(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs