468,513 Members | 979 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,513 developers. It's quick & easy.

c no busy waiting loop

1
Hello,

My question is as follows I have a condition x which I need to signal the current program to begin processing i/o. and when condition x is not met I need the program to sleep. I am pretty sure that the following is correct

while(1)
{
pause();
..
....
}
my question is how do I get it to recognize it's time to send a signal without having it continually poll to see if the condition is met.

//sigHandler defined elsewhere
ie:
signal(SIGHUP,sigHandler); //register signal
while(1)
{
pause(); //have process wait for sig
if( x==4) < -- is this still considered busy wait since it still needs to check to see
//if condition met
{
kill(getpid(),SIGHUP); //where SIGHUP can be any predefined signal in signal.h
}

}

any help would be greatfully appreciated,

Sincerely,

Jim
Nov 21 '07 #1
1 4601
weaknessforcats
9,207 Expert Mod 8TB
You have to continuously poll. Usually you poll and then sleep for a specified number of milliseconds.
Nov 22 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

29 posts views Thread by Paul L. Du Bois | last post: by
4 posts views Thread by Smegly | last post: by
1 post views Thread by marc.gibian | last post: by
12 posts views Thread by Raymond Lewallen | last post: by
1 post views Thread by Michael S. Scherotter | last post: by
3 posts views Thread by vul | last post: by
1 post views Thread by placid | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.