Routine without busy-waiting

S

Smegly

Hi,

I want to write a routine that periodically ( every t seconds) gets a value
from a file
and puts in into a queue.

How can i implement this without getting into a busy-waiting loop . .

i need this to happen in the background of my program .. so everytime t
seconds pass the routine is called . .

Any help would be much appreciated!!

Matt
 
J

Jack Klein

Hi,

I want to write a routine that periodically ( every t seconds) gets a value
from a file
and puts in into a queue.

How can i implement this without getting into a busy-waiting loop . .

Not in standard C, no.
i need this to happen in the background of my program .. so everytime t
seconds pass the routine is called . .

Standard C does not have or define a "background".
Any help would be much appreciated!!

Matt

You will need to use non-standard extensions provided by your
particular compiler/operating system combination to do what you want.
Such extensions are off-topic here. You need to ask in a group that
supports your combination.
 
R

Raju Dantuluri

main()
....
signal(SIGALRM, foo);
....
foo(i);
while(1) {
...
pause();
}

void foo(int s){
//get the message from the file and put it into the queue
...
alarm(1);
}

to make this into a bg process fork it and you need to detach
few things like closing all file descriptors and change pgid etc.

Hope this would work, though I didnt test the code.

Raju
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top