From: 7stud -- Date: 2007-09-28T16:09:27+09:00 Subject: Re: what is mean by thread scheduler in Ruby? Vellingiri Arul wrote: > what is mean by thread scheduler in Ruby?with example? > > > Please Any one help me? > > by > Vellingiri Threads don't execute at the same time despite what the literature might say. If you have two threads, for instance your main program and one thread, then one thread executes for a short time, and then execution switches to the other thread for a short time, and then execution switches back. The switching back and forth happens so fast that it gives the appearance that the threads are executing at the same time. The thread scheduler determines which thread gets execution time and how much. You should note that if both of your threads contain code that has no dead time or pauses in it, your program will take the same amount of time to execute without threads as it does with threads. It's only when code has some pauses in it, like if your program has to wait for a requested web page to be returned, that threads can reduce the time your program takes to execute. During the pauses, the thread scheduler will switch execution to another thread where there is code ready to execute. You can manually manipulate the thread scheduler using methods like wait(), join(), stop(), and pass(). All those methods cause the thread scheduler to alter its normal behavior. puts "Inside main program." sleep(2) #execution halts here - no thread yet puts t = Thread.new do puts <