Search This Blog

Friday, October 16, 2009

Non-preemptive vs Preemptive Thread

Preemptive -- the thread system will interrupt so each thread might get a chance to run. E.g. When a thread with higher priority comes in, the system(OS, or Library) might stop the current running thread and run that new thread with the higher priority.

Main Advantage
: When something takes a long time, the system can interrupt that thread, and run something else. And system can help schedule your thread between different cores.

Disadvantage:
How do you implement the scheduling algorithm? I.e. burden on maintain the kernel and library. And, sometimes, the developer is right, and the system is wrong. (e.g. I want a non-blocking network connection, never wait and never block. and, how does system cooperate on a multicore system? communication between two cores might be expensive and hard to implement(not worth the time))

Non-preemptive(cooperate)
-- once a thread is running, the thread system will keep running the thread till the thread is finished, unless you explicitly suspend the running thread yourself.

Main Advantage:
full control of every thread.

Disadvantage:
Most of the time, the system knows better. e.g. you don't want to wait on a system call forever. It's better off to let system preemptive (interrupt) the system call and run something else. Moreover, system knows much better on scheduling thread among cores (caching, context switching)



reference:
http://stackoverflow.com/questions/817059/what-is-preemption-what-is-a-preemtible-kernel-what-is-it-good-for
http://www.lua.org/pil/9.4.html
http://www.freebsd.org/doc/en/books/arch-handbook/smp-design.html
http://www.cs.utk.edu/~plank/plank/classes/cs360/360/notes/Thread1/lecture.html
http://answers.yahoo.com/question/index?qid=20081016014432AAx85qz
http://en.wikipedia.org/wiki/Computer_multitasking

1 comment:

Anonymous said...

Drugs Similar To Lithium [url=http://snakesandarrowslive.com/]meridia cost[/url] While the medication is going to work on its own, it will be much more effective when combined with a healthy diet and exercise. http://snakesandarrowslive.com/ - buying meridia online