July 2011
Intermediate to advanced
400 pages
8h 46m
English
You can easily verify the priority of the main thread:
main_thread.rb
puts( Thread.main.priority ) #=> 0
So, in the previous program (threads4.rb), if you set the priority of t1 to 2, it will “outrank” the main thread itself and will then be given all the execution time it needs until the next thread, t2, comes along, and so on. By setting the priorities lower than that of the main thread, you can force the three threads to compete only with themselves since the main thread will always outrank them. If you prefer working with positive numbers, you can specifically set the priority of the main thread to a higher value than all other threads:
Thread.main.priority=100
Ruby 1.9 may not respect all values assigned in this way. For ...
Read now
Unlock full access