拡張ライブラリ内での SIGVTALRM

e$B$H$_$?$G$9!#e(B

Ruby e$B$G%9%l%C%[email protected]@.$9$k$He(B SIGVTALRM e$B$,e(B 10ms
e$BKh$KDLCN$5$l$F!"$=$l$Ge(B
Ruby
e$B%9%l%C%I$N%3%s%F%-%9%H%9%$%C%A$,@)8f$5$l$F$$$k$H;W$&$N$G$9$,!J=hM}e(B
e$B7O$K$h$k$+$b!K!"e(BC e$B$G=q$+$l$?e(B Ruby
e$B$N3HD%%i%$%V%i%[email protected])8f$,0$C$F$be(B
SIGVTALRM e$B$ODLCN$5$lB3$1$^$9$h$M!#e(B

e$B3HD%%i%$%V%i%jFb$Ge(B SIGVTALRM
e$B$,$"$,$k$H:$$k$h$&$J>l9g$O!"3HD%%i%$%V%i%je(B
e$BB&$Ge(B rb_thread_stop_timer() e$B$He(B rb_thread_start_timer()
e$B$G=hM}$r3g$k$H$+!"e(B
SIGVTALRM e$B$r%V%m%C%/$9$k$H$+$7$FBP=h$7$J$$$H$$$1$J$$$N$G$7$g$&$+!#e(B

e$B:#$^$G$=$N$h$&$JG<1$OL5$+$C$?$N$G$9$,!e(B Solaris10 e$B>e$Ne(B
MySQL/Ruby e$B<B9Te(B
e$BCf$Ke(B poll() e$B$,e(B SIGVTALRM e$B$Ge(B EINTR
e$B$K$J$C$F<:GT$9$k$H$$$&;v>]$,$$C$?$He(B
e$B$$$&O"Mm$r<u$1$?$N$G!"$I$&$7$?$b$N$+$H!D!#e(B

e$B$3$NJU$K$D$$$FBP=h$7$F$$$k%i%$%V%i%j$r8+$?$3$HL5$$$N$G$9$,!"$I$&$9$k$Ne(B
e$B$,@5$7$$$N$G$7$g$&$+!#e(B

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

In message Re: [ruby-dev:31842] e$B3HD%%i%$%V%i%jFb$G$Ne(B SIGVTALRM
on Mon, 24 Sep 2007 23:03:27 +0900, e$B$H$_$?$^$5$R$me(B
[email protected] writes:

|Ruby e$B$G%9%l%C%[email protected]@.$9$k$He(B SIGVTALRM e$B$,e(B 10ms e$BKh$KDLCN$5$l$F!"$=$l$Ge(B
|Ruby e$B%9%l%C%I$N%3%s%F%-%9%H%9%$%C%A$,@)8f$5$l$F$$$k$H;W$&$N$G$9$,!J=hM}e(B
|e$B7O$K$h$k$+$b!K!"e(BC e$B$G=q$+$l$?e(B Ruby e$B$N3HD%%i%$%V%i%[email protected])8f$,0$C$F$be(B
|SIGVTALRM e$B$ODLCN$5$lB3$1$^$9$h$M!#e(B

e$B$O$$!#e(B

|e$B3HD%%i%$%V%i%jFb$Ge(B SIGVTALRM e$B$,$"$,$k$H:$$k$h$&$J>l9g$O!"3HD%%i%$%V%i%je(B
|e$BB&$Ge(B rb_thread_stop_timer() e$B$He(B rb_thread_start_timer() e$B$G=hM}$r3g$k$H$+!"e(B
|SIGVTALRM e$B$r%V%m%C%/$9$k$H$+$7$FBP=h$7$J$$$H$$$1$J$$$N$G$7$g$&$+!#e(B

SIGVTALRMe$B$r$I$&$7$F$b%V%m%C%/$9$kI,MW$,$"$k$N$G$"$l$P!"$=$&$Je(B
e$B$k$H;W$$$^$9!#e(B

|e$B:#$^$G$=$N$h$&$JG<1$OL5$+$C$?$N$G$9$,!e(B Solaris10 e$B>e$Ne(B MySQL/Ruby e$B<B9Te(B
|e$BCf$Ke(B poll() e$B$,e(B SIGVTALRM e$B$Ge(B EINTR e$B$K$J$C$F<:GT$9$k$H$$$&;v>]$,$$C$?$He(B
|e$B$$$&O"Mm$r<u$1$?$N$G!"$I$&$7$?$b$N$+$H!D!#e(B
|
|e$B$3$NJU$K$D$$$FBP=h$7$F$$$k%i%$%V%i%j$r8+$?$3$HL5$$$N$G$9$,!"$I$&$9$k$Ne(B
|e$B$,@5$7$$$N$G$7$g$&$+!#e(B

[email protected]$7$$!W$O3NN)$5$l$F$$$J$$$h$&$K;W$$$^$9!#K\Ev$Oe(BSA_RESTART
e$B$r;XDj$9$k$N$,$h$$$N$+$b$7$l$J$$$N$G$9$,!"$=$l$O$=$l$G2a5n$Ke(B
e$BLdBj$r0z$-5/$3$7$?$h$&$J5$$,$7$^$9$7!#e(B

e$B$H$_$?$G$9!#e(B

On Mon, 24 Sep 2007 23:32:22 +0900
Yukihiro M. [email protected] wrote:

|e$B3HD%%i%$%V%i%jFb$Ge(B SIGVTALRM e$B$,$"$,$k$H:$$k$h$&$J>l9g$O!"3HD%%i%$%V%i%je(B
|e$BB&$Ge(B rb_thread_stop_timer() e$B$He(B rb_thread_start_timer() e$B$G=hM}$r3g$k$H$+!"e(B
|SIGVTALRM e$B$r%V%m%C%/$9$k$H$+$7$FBP=h$7$J$$$H$$$1$J$$$N$G$7$g$&$+!#e(B

SIGVTALRMe$B$r$I$&$7$F$b%V%m%C%/$9$kI,MW$,$"$k$N$G$"$l$P!"$=$&$Je(B
e$B$k$H;W$$$^$9!#e(B

e$BN;2r$G$9!#e(BRuby e$B$N%j%3%s%Q%$%k$,$G$-$k>u67$G$"$l$P!"e(Bconfigure
enable-pthread e$B$G$b2r7h$7$^$9$h$M!#$*$=$i$/!#e(B

|e$B:#$^$G$=$N$h$&$JG<1$OL5$+$C$?$N$G$9$,!e(B Solaris10 e$B>e$Ne(B MySQL/Ruby e$B<B9Te(B
|e$BCf$Ke(B poll() e$B$,e(B SIGVTALRM e$B$Ge(B EINTR e$B$K$J$C$F<:GT$9$k$H$$$&;v>]$,$$C$?$He(B
|e$B$$$&O"Mm$r<u$1$?$N$G!"$I$&$7$?$b$N$+$H!D!#e(B
|
|e$B$3$NJU$K$D$$$FBP=h$7$F$$$k%i%$%V%i%j$r8+$?$3$HL5$$$N$G$9$,!"$I$&$9$k$Ne(B
|e$B$,@5$7$$$N$G$7$g$&$+!#e(B

[email protected]$7$$!W$O3NN)$5$l$F$$$J$$$h$&$K;W$$$^$9!#K\Ev$Oe(BSA_RESTART
e$B$r;XDj$9$k$N$,$h$$$N$+$b$7$l$J$$$N$G$9$,!"$=$l$O$=$l$G2a5n$Ke(B
e$BLdBj$r0z$-5/$3$7$?$h$&$J5$$,$7$^$9$7!#e(B

e$B$H$j$"$($:!"e(Benable-pthread
e$B$r;n$7$F$_$F$HEA$($F$*$-$^$7$?!#e(B

Solaris
e$B$G$O!"$+$J$jA0e(B([ruby-dev:17878])e$B$K$bF1$8$h$&$JLdBj$,5/$-$?$3$He(B
e$B$,$"$k$N$G!">o$Ke(B --enable-pthread
e$B$7$H$$$?J}$,L5Fq$J$N$+$b$7$l$^$;$s!#e(B

setitimer(ITIMER_VIRTUAL) e$B$O%f!<%6!<6u4V$G$Ne(B CPU

e$B;~4V$,%+%&%s%H$5$l$ke(B

[email protected]$H;W$C$F$$$?$N$G!"%7%9%F%`%3!<%kCf$Ke(B SIGVTALRM

e$B$,H/@8$9$k$N$,ITe(B

e$B;W5D!#$=$&$$$&$b$N$G$O$J$$$N$+$J!D!#e(B

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

In message Re: [ruby-dev:31859] Re: e$B3HD%%i%$%V%i%jFb$G$Ne(B
SIGVTALRM
on Wed, 26 Sep 2007 00:21:26 +0900, e$B$H$_$?$^$5$R$me(B
[email protected] writes:

|# setitimer(ITIMER_VIRTUAL) e$B$O%f!<%6!<6u4V$G$Ne(B CPU e$B;~4V$,%+%&%s%H$5$l$ke(B
|# [email protected]$H;W$C$F$$$?$N$G!"%7%9%F%`%3!<%kCf$Ke(B SIGVTALRM e$B$,H/@8$9$k$N$,ITe(B
|# e$B;W5D!#$=$&$$$&$b$N$G$O$J$$$N$+$J!D!#e(B

e$B!V%W%m%;%9$N<B9T;~4V!W$K$O%f!<%6!<[email protected]$1$G$J$/%7%9%F%%3!<e(B e$B%k$K$h$k$b$N$b4^$$h$&$G$9!#%f!<%6!<6u4V$N<B9T;~4V$K$h$k%?%$e(B
e$B%^!<$bM_$7$$$G$9$h$M$(!#e(B

In article [email protected],
e$B$H$_$?$^$5$R$me(B [email protected] writes:

Solaris e$B$G$O!"$+$J$jA0e(B([ruby-dev:17878])e$B$K$bF1$8$h$&$JLdBj$,5/$-$?$3$He(B
e$B$,$"$k$N$G!">o$Ke(B --enable-pthread e$B$7$H$$$?J}$,L5Fq$J$N$+$b$7$l$^$;$s!#e(B

enable-pthread [email protected]$He(B

% ./ruby -ve Thread.new {}
r, w = IO.pipe
r.sysread(10)
ruby 1.8.6 (2007-09-26 patchlevel 5000) [i686-linux]
-e:3:in `sysread: Interrupted system call (Errno::EINTR)
from -e:3

e$B$H$+!"e(B

% ./ruby -rnet/http -e
Thread.new {}
h = Net::HTTP.new(www.ruby-lang.org)
h.read_timeout = nil
h.get("/")
/home/akr/ruby/18pth/lib/ruby/1.8/net/protocol.rb:135:in `sysread:
Interrupted system call (Errno::EINTR)

e$B$H$+!"e(B

% ./ruby -e Thread.new {}
r, w = IO.pipe
p w.syswrite(a * 1024 * 1024)
p w.syswrite(a * 1024 * 1024)
65536
-e:4:in `syswrite: Interrupted system call (Errno::EINTR)
from -e:4

e$B$H$+!"e(B

nute(5:32:01)% ./ruby -e
Thread.new { }
n = 5000
w = STDOUT
loop {
w.write(a * n)
w.write(b * n)
w.flush
}
'|./ruby -e
n = 5000
r = STDIN
loop {
sleep 0.1
s = r.read(n); p [s.length, s.squeeze]
sleep 0.1
s = r.read(n); p [s.length, s.squeeze]
}

[5000, a]
[5000, b]
[5000, a]
[5000, b]
[5000, a]
[5000, b]
[5000, a]
[5000, b]
[5000, a]
[5000, b]
[5000, a]
[5000, b]
[5000, a]
[5000, ba]
[5000, ab]
[5000, ba]
[5000, aba]
[5000, ab]

% ./ruby -v
ruby 1.8.6 (2007-09-26 patchlevel 5000) [i686-linux]

e$B$H$+5/$-$k$7$J$!!#$=$l$O$=$l$G$J$+$J$+!#e(B

e$B$J$*!"$3$3$G;H$C$F$$$ke(B ./ruby e$B$Oe(B --enable-pthread
e$B$G$9!#e(B

setitimer(ITIMER_VIRTUAL) e$B$O%f!<%6!<6u4V$G$Ne(B CPU e$B;~4V$,%+%&%s%H$5$l$ke(B

[email protected]$H;W$C$F$$$?$N$G!"%7%9%F%`%3!<%kCf$Ke(B SIGVTALRM e$B$,H/@8$9$k$N$,ITe(B

e$B;W5D!#$=$&$$$&$b$N$G$O$J$$$N$+$J!D!#e(B

e$B$3$N7o$,$=$&$G$"$k$+$I$&$+$O$o$+$j$^$;$s$,!"e(B
setitimer(ITIMER_VIRTUAL) e$B$,%7%9%F%`%3!<%kCf$Ke(B SIGVTALRM e$B$re(B
e$B0z$-5/$3$9Nc$r$R$H$DCN$C$F$$$^$9!#e(B

e$B3HD%%i%$%V%i%j$,FbItE*$K%M%$%F%#%V%9%l%C%I$r;H$C$F$$$F!"$=$Ne(B
e$B%M%$%F%#%V%9%l%C%I$,e(B SIGVTARLM e$B$r%^%9%/$7$F$$$k>l9g$K$O!e(B
SIGVTARLM e$B$,%7%9%F%%3!<%kCf$KH/@8$9$k$3$H$,$"$j$^$9!#$=$N%Me(B e$B%$%F%#%V%9%l%C%I$,%f!<%6!<6u4V$G$Ne(B CPU e$B;~4V$r>CHq$7$F%?%$%^e(B e$B$,H/2P$7$?;~$=$N%M%$%F%#%V%9%l%C%I$,%7%0%J%k$r<u$1IU$1$J$$>le(B e$B9g!"B>$N!"%7%9%F%%3!<%k$G%V%m%C%/$7$F$$$k%9%l%C%I$K%7%0%J%ke(B
e$B$,E~Ce$9$k!$H$$$&%9%H!<%j!<$_$?$$$G$9!#e(B

% cat extconf.rb
require mkmf
have_library(pthread)
create_makefile(pth)
% cat pth.c
#include <stdlib.h>
#include <errno.h>
#include <signal.h>
#include <pthread.h>

static void *
loop(void *arg)
{
sigset_t sigset;
int ret;

if (sigfillset(&sigset) == -1) { perror(sigfillset); exit(1); }
ret = pthread_sigmask(SIG_BLOCK, &sigset, NULL);
if (ret != 0) { perror(pthread_sigmask); exit(1); }

while (1);
}

void
Init_pth()
{
pthread_t pth;
int ret;
ret = pthread_create(&pth, NULL, loop, NULL);
if (ret != 0) { errno = ret; perror(pthread_create); exit(1); }
}

% ruby-1.8 extconf.rb
checking for main() in -lpthread yes
creating Makefile
% make
gcc -I. -I. -I/home/akr/ruby/18/lib/ruby/1.8/i686-linux -I. -fPIC -g
-O2 -c pth.c
gcc -shared -o pth.so pth.o -L. -L/home/akr/ruby/18/lib
-Wl,-R/home/akr/ruby/18/lib -L. -rdynamic -Wl,-export-dynamic
-lpthread -ldl -lcrypt -lm -lc
% ruby-1.8 -rpth -e
Thread.new {}
r, w = IO.pipe
r.sysread(10)
-e:4:in `sysread: Interrupted system call (Errno::EINTR)
from -e:4
zsh: exit 1 ruby-1.8 -rpth -e Thread.new {} r, w = IO.pipe
r.sysread(10)
% strace ruby-1.8 -rpth -e
Thread.new {}
r, w = IO.pipe
r.sysread(10)

read(3, 0x8135308, 10) = ? ERESTARTSYS (To be
restarted)
SIGVTALRM (Virtual timer expired) @ 0 (0)
sigreturn() = ? (mask now [])

% ruby-1.8 -v
ruby 1.8.6 (2007-09-26 patchlevel 5000) [i686-linux]

e$B$J$*!"$3$Ne(B ruby-1.8 e$B$Oe(B --enable-pthread
e$B$G$O$"$j$^$;$s!#e(B

e$B$H$_$?$G$9!#e(B

On Wed, 26 Sep 2007 00:21:26 +0900
e$B$H$_$?$^$5$R$me(B [email protected] wrote:

e$BN;2r$G$9!#e(BRuby e$B$N%j%3%s%Q%$%k$,$G$-$k>u67$G$"$l$P!"e(Bconfigure
enable-pthread e$B$G$b2r7h$7$^$9$h$M!#$$=$i$/!#e(B
e$B!A!Ae(B
e$B$H$j$"$($:!"e(Benable-pthread e$B$r;n$7$F$_$F$HEA$($F$
$-$^$7$?!#e(B

e$B2r7h$7$J$+$C$?$h$&$G$9e(B (;

eval.c e$B$Ne(B thread_timer() e$B$,%7%9%F%`%3!<%kCf$Ke(B SIGVTALRM
e$B$rAw$k$3$H$,$"e(B
e$B$k$h$&$G!D!#e(B

| if (!rb_thread_critical) {
| rb_thread_pending = 1;
| if (rb_trap_immediate) { e$B"+e(B (a)
| pthread_kill(ruby_thid, SIGVTALRM); e$B"+e(B (b)
| }
| }

e$B$3$NJU$j$N%3!<%I$C$F!"2?$NGSB>@)8f$b$J$7$Ke(B rb_thread_critical
e$B$de(B
rb_trap_immediate
e$BJQ?t$,;2>H$5$l$F$$$k$h$&$J$s$G$9$,!"LdBj$J$$$s$G$7$ge(B
e$B$&$+!#e(B

(a) e$B$G$Oe(B rb_trap_immediate e$B$Oe(B 1 [email protected]$C$?$1$I!e(B(b)
e$B$N;[email protected]$G$Oe(B 0 e$B$K$J$C$F$$e(B
e$B$F!%a%$%s%9%l%C%I=hM}$NJQ$J$H$3$m$G3d$j9~$_$,F~$k$J$s$F$3$H$O$J$$!)e(B

e$B$H$3$m$G!"?!9;n$7$F$F$o$+$C$?$s$G$9$,!"e(BRuby
e$B$N%9%l%C%I$O!"Aj<j$,$$$J$$e(B
e$B%Q%$%W$Ne(B open
e$B$G$O%V%m%C%/$7$A$c$&$s$G$9$M!#:#$^$GCN$j$^$;$s$G$7$?!#e(B

$ mknod /tmp/pipe p
$ ruby -e Thread.new{sleep 0.1; File.open("/tmp/pipe")};
10000.times{|i| p i}

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

In message Re: [ruby-dev:31903] Re: e$B3HD%%i%$%V%i%jFb$G$Ne(B
SIGVTALRM
on Sat, 29 Sep 2007 22:16:58 +0900, e$B$H$_$?$^$5$R$me(B
[email protected] writes:

|> e$B$H$j$"$($:!"e(Benable-pthread e$B$r;n$7$F$_$F$HEA$($F$*$-$^$7$?!#e(B
|
|e$B2r7h$7$J$+$C$?$h$&$G$9e(B (;
|
|eval.c e$B$Ne(B thread_timer() e$B$,%7%9%F%`%3!<%kCf$Ke(B SIGVTALRM e$B$rAw$k$3$H$,$"e(B
|e$B$k$h$&$G!D!#e(B

e$B$&!<$`!#e(B

|| if (!rb_thread_critical) {
|| rb_thread_pending = 1;
|| if (rb_trap_immediate) { e$B"+e(B (a)
|| pthread_kill(ruby_thid, SIGVTALRM); e$B"+e(B (b)
|| }
|| }
|
|e$B$3$NJU$j$N%3!<%I$C$F!"2?$NGSB>@)8f$b$J$7$Ke(B rb_thread_critical e$B$de(B
|rb_trap_immediate e$BJQ?t$,;2>H$5$l$F$$$k$h$&$J$s$G$9$,!"LdBj$J$$$s$G$7$ge(B
|e$B$&$+!#e(B
|
|(a) e$B$G$Oe(B rb_trap_immediate e$B$Oe(B 1 [email protected]$C$?$1$I!e(B(b) e$B$N;[email protected]$G$Oe(B 0 e$B$K$J$C$F$$e(B
|e$B$F!%a%$%s%9%l%C%I=hM}$NJQ$J$H$3$m$G3d$j9~$_$,F~$k$J$s$F$3$H$O$J$$!)e(B

[email protected]$O$"$k$G$7$g$&$M!#$I$N$/$i$$0-1F6A$,$"[email protected]$b$l$^e(B
e$B$;$s$,!#e(B

|e$B$H$3$m$G!"?!9;n$7$F$F$o$+$C$?$s$G$9$,!"e(BRuby e$B$N%9%l%C%I$O!"Aj<j$,$$$J$$e(B
|e$B%Q%$%W$Ne(B open e$B$G$O%V%m%C%/$7$A$c$&$s$G$9$M!#:#$^$GCN$j$^$;$s$G$7$?!#e(B

e$B$($(!e(Bstdioe$B$Ge(BNONBLOCKINGe$B$Je(Bopene$B$r9T$&J}K!$,$o$+$i$J$+$C$?$s$G!#e(B
[email protected]$He(Bstdioe$B$r<N$F$F$$$k$N$G%V%m%C%/$7$^$;$s!#$G$b![email protected]$+e(B
e$B3d$j9~$_$,[email protected]$J$"!#e(B

e$B$H$_$?$G$9!#e(B

On Sat, 29 Sep 2007 22:16:58 +0900
e$B$H$_$?$^$5$R$me(B [email protected] wrote:

e$BN;2r$G$9!#e(BRuby e$B$N%j%3%s%Q%$%k$,$G$-$k>u67$G$"$l$P!"e(Bconfigure
enable-pthread e$B$G$b2r7h$7$^$9$h$M!#$$=$i$/!#e(B
e$B!A!Ae(B
e$B$H$j$"$($:!"e(Benable-pthread e$B$r;n$7$F$_$F$HEA$($F$
$-$^$7$?!#e(B

e$B2r7h$7$J$+$C$?$h$&$G$9e(B (;

e$B7k6I!":#2s$N7o$Oe(B [ruby-dev:31842] e$B$Ne(B

| rb_thread_stop_timer() e$B$He(B rb_thread_start_timer() e$B$G=hM}$r3g$ke(B

e$B$H$$$&J}K!$GBP=h$7$^$7$?!#$H$j$"$($::#2s$N8=>]$K$D$$$F$O<}$^$C$?$h$&$G$9!#e(B

MySQLe$B8GM-$NLdBj$G$O$J$$$H;W$&$7!e(BSolarise$B8GM-$C$]$$$N$G!:#2s$NJQ99$re(B
MySQL/Ruby e$B$K<h$j9~$`$+$I$&$+LB$C$F$^$9!#e(B

enable-pthread e$B;~$N8=>]$r$b$&$A$g$C$HD4$Y$F$_$h$&$+$J!D!#e(B

e$B$H$_$?$G$9!#e(B

On Wed, 26 Sep 2007 02:35:08 +0900
Yukihiro M. [email protected] wrote:

|# setitimer(ITIMER_VIRTUAL) e$B$O%f!<%6!<6u4V$G$Ne(B CPU e$B;~4V$,%+%&%s%H$5$l$ke(B
|# [email protected]$H;W$C$F$$$?$N$G!"%7%9%F%`%3!<%kCf$Ke(B SIGVTALRM e$B$,H/@8$9$k$N$,ITe(B
|# e$B;W5D!#$=$&$$$&$b$N$G$O$J$$$N$+$J!D!#e(B

e$B!V%W%m%;%9$N<B9T;~4V!W$K$O%f!<%6!<[email protected]$1$G$J$/%7%9%F%%3!<e(B e$B%k$K$h$k$b$N$b4^$$h$&$G$9!#%f!<%6!<6u4V$N<B9T;~4V$K$h$k%?%$e(B
e$B%^!<$bM_$7$$$G$9$h$M$(!#e(B

Linux
e$B$N%=!<%9$rD/$a$F$_$?$s$G$9$,!"0l1~%f!<%6!<;[email protected]$1$r?t$($F$$$k$he(B
e$B$&$K8+$($^$7$?!#e(B

kernel/posix-cpu-timers.c e$B$N<!$NJU$j!#e(B
| if (cputime_ge(utime, sig->it_virt_expires)) {
| /* ITIMER_VIRTUAL fires and reloads. */
| sig->it_virt_expires = sig->it_virt_incr;
| if (!cputime_eq(sig->it_virt_expires, cputime_zero)) {
| sig->it_virt_expires = cputime_add(
| sig->it_virt_expires, utime);
| }
| __group_send_sig_info(SIGVTALRM, SEND_SIG_PRIV, tsk);
| }

e$B$G$b!"e(BSolaris e$B$bF1MM$J$s$G$9$h$M!D!#e(B

uts/common/os/clock.c:
| /*
| * If CPU was in user state, process lwp-virtual time
| * interval timer.
| */
| if (user_mode &&
| timerisset(&lwp->lwp_timer[ITIMER_VIRTUAL].it_value) &&
| itimerdecr(&lwp->lwp_timer[ITIMER_VIRTUAL], usec_per_tick) == 0) {
| poke = 1;
| sigtoproc(pp, t, SIGVTALRM);
| }

e$B2?8Ne(B Solaris e$B$G$O%7%9%F%`%3!<%kCf$Ge(B SIGVTALRM
e$B$,H/@8$9$k$N$d$i!D!#e(B

e$B$5$H$&$U$_$d$9e(B @ OSS e$B%F%/%N%m%8$G$9!#e(B

At Mon, 24 Sep 2007 23:03:27 +0900,
e$B$H$_$?$^$5$R$me(B wrote:

e$B:#$^$G$=$N$h$&$JG<1$OL5$+$C$?$N$G$9$,!e(B Solaris10 e$B>e$Ne(B MySQL/Ruby e$B<B9Te(B
e$BCf$Ke(B poll() e$B$,e(B SIGVTALRM e$B$Ge(B EINTR e$B$K$J$C$F<:GT$9$k$H$$$&;v>]$,$$C$?$He(B
e$B$$$&O"Mm$r<u$1$?$N$G!"$I$&$7$?$b$N$+$H!D!#e(B

e$B:#EYe(B Solaris 10 e$B$Ge(B Ruby e$B$r;n$=$&$H;W$C$F$$$?$N$Ge(B
e$B5$$K$J$C$?$N$G;n$7$F$_$^$7$?!#e(BC e$B$N%=!<%9$O0J2<e(B:

#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <poll.h>
#include <errno.h>
#include <sys/time.h>

int sig_vtalrm_count = 0;

void sig_vtalrm(int sig)
{
printf("******** SIGVTALRM (%d) ********\n", sig);
sig_vtalrm_count++;
}

int main(void)
{
struct sigaction sigact;
int i, j;

struct itimerval itime, itime2;
struct pollfd fds[1];
int fd_ready;
int poll_count = 0;

int itime_timeout = 100; /* 100 msec /
int poll_timeout = 1000; /
1000 msec */

sigact.sa_handler = sig_vtalrm;
sigact.sa_flags = 0;
sigaction(SIGVTALRM, &sigact, NULL);

itime.it_interval.tv_sec = itime.it_value.tv_sec = 0L;
itime.it_interval.tv_usec = itime.it_value.tv_usec = itime_timeout *
1000L;
errno = 0;
setitimer(ITIMER_VIRTUAL, &itime, NULL);
printf(setitimer errno %d (%s)\n, errno, strerror(errno));

fds[0].fd = 0;
fds[0].events = POLLIN;
for (i = 0; i < 10; i++) {
getitimer(ITIMER_VIRTUAL, &itime2);
printf(pre poll : gettimer %ld sec, %ld usec\n,
itime2.it_value.tv_sec, itime2.it_value.tv_usec);
errno = 0;
fd_ready = poll(fds, 1L, poll_timeout);
poll_count++;
printf(poll fd ready %d\n, fd_ready);
printf(poll fd events %x\n, fds[0].revents);
printf(poll errno %d (%s)\n, errno, strerror(errno));
getitimer(ITIMER_VIRTUAL, &itime2);
printf(post poll: gettimer %ld sec, %ld usec\n,
itime2.it_value.tv_sec, itime2.it_value.tv_usec);
for (j = 0; j < 0xFFFFFF; j++) {}
}

puts("");
printf(poll count: %d (%d msec)\n, poll_count, poll_count *
poll_timeout);
printf(sigvtalrm count: %d (%d sec)\n, sig_vtalrm_count,
sig_vtalrm_count * itime_timeout);

return 0;
}

poll(2) e$B$be(B set/getitimer(2) e$B$b=i$a$F;H$&$N$G<+?.$,$J$$e(B
e$B$G$9$,!"$"$C$F$^$9$+$Me(B? e$B%3%s%Q%$%kJ}K!$H<B9T<j=g$Oe(B:

$ /usr/sfw/bin/gcc -Wall a.c && time ./a.out
$ /usr/sfw/bin/gcc -D_REENTRANT -lthread -Wall a.c && time ./a.out
$ /opt/SUNWspro/bin/cc a.c && time ./a.out
$ /opt/SUNWspro/bin/cc -D_REENTRANT -lthread a.c && time ./a.out
$ /opt/SUNWspro/bin/cc -mt a.c && time ./a.out

e$B$$$:$l$b7k2L$O0J2<$N$h$&$K$J$j!"e(Bpoll() e$B$Ge(B EINTR
e$B$OH/@8$7$^$;$s$G$7$?e(B
(SPARC, Intel e$B$H$be(B):

$ /usr/sfw/bin/gcc -Wall a.c && time ./a.out
setitimer errno 0 (Error 0)
pre poll : gettimer 0 sec, 100000 usec
poll fd ready 0
poll fd events 0
poll errno 0 (Error 0)
post poll: gettimer 0 sec, 100000 usec
pre poll : gettimer 0 sec, 40000 usec
poll fd ready 0
poll fd events 0
poll errno 0 (Error 0)
post poll: gettimer 0 sec, 40000 usec
******** SIGVTALRM (28) ********
pre poll : gettimer 0 sec, 100000 usec
poll fd ready 0
poll fd events 0
poll errno 0 (Error 0)
post poll: gettimer 0 sec, 100000 usec
pre poll : gettimer 0 sec, 30000 usec
poll fd ready 0
poll fd events 0
poll errno 0 (Error 0)
post poll: gettimer 0 sec, 30000 usec
******** SIGVTALRM (28) ********
pre poll : gettimer 0 sec, 60000 usec
poll fd ready 0
poll fd events 0
poll errno 0 (Error 0)
post poll: gettimer 0 sec, 60000 usec

*** e$B>JN,e(B ***

poll count: 10 (10000 msec)
sigvtalrm count: 6 (600 sec)

real 0m10.735s
user 0m0.650s
sys 0m0.013s

e$B$3$NJU$K$D$$$FBP=h$7$F$$$k%i%$%V%i%j$r8+$?$3$HL5$$$N$G$9$,!"$I$&$9$k$Ne(B
e$B$,@5$7$$$N$G$7$g$&$+!#e(B

SIGVTALRM e$B$Ge(B poll(2) e$B$,e(B EINTR
e$B$K$J$k$+$I$&$+$O$H$b$+$/!e(B
poll(2) e$B$Ge(B EINTR e$B$,H/@[email protected]$O$$k$N$G!"e(B
EINTR e$B$rJdB-$7$F$$$J$$%i%$%V%i%j$,0-$$$s$8$c$J$$$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