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.

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))

-- 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.

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)


1 comment:

Anonymous said...

Drugs Similar To Lithium [url=]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. - buying meridia online