Threads

Threads can compute mutliple things at once. Threads run in same address space in a process.

Threads are in a queue. Schduler schedule threads for execution.

Preemptive Scheduling

Scheduler keeps a timer. Scheduler interrupts threads when a thread has completed number of steps (timeslice, quantum), put it back to ready queue. And a new thread selected from ready queue to run.

Preemption

In Ruby

thread = Thread.new { puts "Hello, thread!" }
thread.join

https://github.com/ruby/ruby/blob/master/thread.c