On Wed, Oct 10, 2012 at 6:49 PM, V G wrote: > Hi all, I have a question about CPU load, task scheduling, and how a real > operating system (like Linux/BSD/QNX) manage threads. > > Q: If you write a simple, single-threaded program in C as follows > > int main() { while(1); } > > and run it on a single core CPU, the CPU load shoots up to 1.00 and stays > there. Makes sense, as all of the CPU time is spent in this thread. (All = as > in almost all, since the operating system's task scheduler and other > processes have to run as well.) What you have done is a busy loop, CPU spends all the time in there. > However, many single threaded network event loop libraries, as well as GU= I > libraries come with their own main loop/event loop. Your program will nev= er > exit from the main loop unless you kill it, but while the program is > running, the CPU does NOT appear to be under load. What's going on here? > How is it that the main loop is running and is responsive, yet the CPU is > under minimal load? generally they make use of poll/select http://www.makelinux.net/ldd3/chp-6-sect-3 or use a thread instead http://www.yolinux.com/TUTORIALS/LinuxTutorialPosixThreads.html --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .