Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Semaphores and CPU usage relationship

Status
Not open for further replies.

mighk

Programmer
Aug 9, 2002
2
0
0
PH
When a thread is blocked at a semaphore (e.g. in semop()), does the thread really become idle (no operations), or will it poll inside the semop() operation waiting for a free resource? I have this multithreaded program that when all threads are blocked at semop(), the CPU usage does not go below 7% even when all threads are at idle state. I'd appreciate any help 'coz I can't figure this out.
 
I'm assuming UNIX here, so stop me if...

A blocking call does sleep the thread itself. However - the "SYSTEM CALL" itself may still be doing work on your thread's behalf. Any case where you have several blocked calls, it is likely that your Kernel is trying to keep up with your hardware (moving memory around, swapping to disk, etc). In no case should your CPU be completly idle while you have blocked threads. The Kernel has to be attempting to clear all other operations.

Look at your system and processes with a program like "top". You should notice that the bulk of your processing time (even a measly 7%) is being taken up by the System, not by your user processes.
 
Tnx for the insight man. But i wonder why this doesn't happen after my program has finished initialization were all the threads are blocked at semop(). cpu usage at this state is bellow 1%. after i run the program ( a thread calls semop(+) ), the cpu usage starts to rise (understandably). But when i stop the program ( semop(-) til there are no more sem resource) the cpu usage gets stuck at 7%. i now it's not big usage but i'm wondering why it doesn't go below this whereas all threads stop at the same semop operation during initialization. i placed printing in all my threads before the semop operation and i'm pretty sure all threads stopped there. Does this mean the the "system call" does not do anything internally after the initialization phase of the process but does so after i have "run" my program?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top