e$B1sF#$H?=$7$^$9!#e(B
Thread#priority= e$B$K$h$kM%@hEY$N@_Dj$,$G$-$J$$$h$&$G$9!#e(B
e$B0J2<$Oe(B Thread#priority=
e$B$N%3%a%s%H$K=q$$$F$"$k%5%s%W%k%3!<%I$G$9$,!"e(B
e$B%3%a%s%H$NDL$j$KF0$-$^$;$s!#e(B
$ ./ruby -ve ’
count1 = count2 = 0
a = Thread.new do
loop { count1 += 1 }
end
a.priority = -1
b = Thread.new do
loop { count2 += 1 }
end
b.priority = -2
sleep 1
p count1 #=> 622504
p count2 #=> 5832
’
ruby 1.9.0 (2008-01-15 revision 0) [i686-linux]
3196560
3359563
Thread#priority= e$B$N<B8=$Ke(B pthread
e$B$NM%@hEY$r;H$&@oN,$N$h$&$G$9$,!“e(B
e$B$3$l$K$OLdBj$,$”$k$H;W$$$^$9!#e(B
- pthread e$B$N%G%U%)%k%H$N%9%1%8%e!<%j%s%0%"%k%4%j%:%`e(B (SCHED_OTHER)
e$B$Oe(B
e$BM%@hEY$rL5;k$9$ke(B - e$BM%@hEY$r9MN8$7$F$/$l$k%9%1%8%e!<%j%s%0e(B (SCHED_RR e$B$He(B
SCHED_FIFO) e$B$Oe(B
e$B%9!<%Q!<%P%$%68"8B$,$J$$$H;H$($J$$$i$7$$e(B (e$B>/$J$/$H$be(B LInux
e$B$G$Oe(B)
e$B$3$N$h$&$J@)Ls$,$"$k0J>e!"e(Bpthread
e$B$NM%@hEY$r;H$&$N$OFq$7$$$H;W$$$^$9!#e(B
e$B2r7hJ}K!$re(B 2 e$B$DDs0F$7$^$9!#e(B
(1) Thread#priority= e$B$re(B deprecated e$B$9$ke(B
(2) native_thread_yield e$B$9$k$H$-$Oe(B priority
e$B$N?t$@$17+$jJV$7$Fe(B
e$B5<;wE*$KM%@hEY$r<B8=$9$ke(B
e$B0J2<$Oe(B (2) e$B$N<BAu%$%a!<%8$G$9!#e(Bthread_win32
e$B$O$H$j$"$($:L5;k$7$F$^$9!#e(B
Index: thread.c
— thread.c (revision 15066)
+++ thread.c (working copy)
@@ -676,13 +676,16 @@
thread_debug(“rb_thread_schedule\n”);
if (!rb_thread_alone()) {
rb_thread_t *th = GET_THREAD();
-
int priority = th->priority;
thread_debug(“rb_thread_schedule/switch start\n”);
rb_gc_save_machine_context(th);
native_mutex_unlock(&th->vm->global_interpreter_lock);
{
-
native_thread_yield();
-
while(priority++ < 0) {
- native_thread_yield();
-
}}
native_mutex_lock(&th->vm->global_interpreter_lock);
e$B$D$$$G$G$9$,!"2>$Ke(B pthread
e$B$NM%@hEY$,$&$^$/;H$($?$H$7$F$b!"8=:_$Ne(B
native_thread_apply_priority e$B$Oe(B min/max
e$B$N%A%’%C%/$,$J$s$+JQ$Je(B
e$B5$$,$7$^$9!#e(B
Index: thread_pthread.c
— thread_pthread.c (revision 15066)
+++ thread_pthread.c (working copy)
@@ -355,12 +355,12 @@
max = sched_get_priority_max(policy);
min = sched_get_priority_min(policy);
- if (min < priority) {
- if (min > priority) {
- priority = min;
- }
- else if (max < priority) {
priority = max;
}
-
else if (max > priority) {
-
priority = min;
-
}
sp.sched_priority = priority;
pthread_setschedparam(th->thread_id, policy, &sp);