Your main loop would cause 100% loading, depending how=20 "poll_my_sockets()" worked... If you write it like this int main() { while(1) { let_me_know_if_my_sockets_need_attention();=20 do_work(); } } then your program is spending most of it's time waiting for something=20 to happen. "select" is your friend :) On 2012-10-10 09:19, V G wrote: > Hi all, I have a question about CPU load, task scheduling, and how a=20 > 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=20 > stays > there. Makes sense, as all of the CPU time is spent in this thread.=20 > (All as > in almost all, since the operating system's task scheduler and other > processes have to run as well.) > > However, many single threaded network event loop libraries, as well=20 > as GUI > libraries come with their own main loop/event loop. Your program will=20 > never > 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=20 > here? > How is it that the main loop is running and is responsive, yet the=20 > CPU is > under minimal load? > > Even if you did something like this, > > int main() { while(1) { poll_my_sockets(); do_work(); } } > > wouldn't it use 100% of the CPU's time in the main loop? But it=20 > appears > that all asynchronous network libraries somehow don't load up the=20 > CPU. Yes, > CPU load is the indicator of actual CPU load, and doesn't factor in > anything that's waiting on I/O, but shouldn't just the act of calling=20 > the > poll function in an infinite loop still fully load the CPU? --=20 http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist .