Ruby/Threads/priority

Материал из Wiki.crossplatform.ru

(Различия между версиями)
Перейти к: навигация, поиск
м (1 версия: Импорт выборки материалов по Ruby)
 

Текущая версия на 18:00, 13 сентября 2010

Thread Priority

$slow = 0
$fast = 0
(Thread.new { loop { $slow += 1 } }).priority = -2
(Thread.new { loop { $fast += 1 } }).priority = -1
sleep 1
Thread.critical = true
puts "The slow thread counted to #{$slow}"
puts "The fast thread counted to #{$fast}"
 
# The slow thread counted to 11675
# The fast thread counted to 629474



What is your priority

t1 = Thread.new { loop { sleep 1 } }
t2 = Thread.new { loop { sleep 1 } }
t2.priority = 3    # Set t2 at priority 3
p1 = t1.priority   # 0
p2 = t2.priority   # 3