Application Timeslicing

Brian Blietz bblietz@iastate.edu
Mon Mar 1 07:31:00 GMT 2004


Is there anyway to allow an application to give up just its timeslice?

What I would like to do is poll a counter, and if it hasn't changed,
I would like to just give up the rest of my timeslice.
(I am trying to avoid the kernel overhead of semaphores and such.)

I have read somewhere that ring buffers are used for speedy IPC without 
system calls.  But
there has to be some way to avoid race conditions between the two processes.

What would sleep(0) do exactly?
Would sleep say "Hey, you want to sleep for zero time, so I'll just 
return control back to you",
or would it say "Well since you called me, you are losing your timeslice 
no matter what,
but you will be ready to run the next time the scheduler sees fit"?


Here is basically the code sequence

Process 1 (Consumer):
while(counter == 0)
    give up timeslice;

Process 2 (Producer):
while(counter == MAX_COUNT)
    give up timeslice;

(In my particular scenario, the producer will most likely produce much 
faster than the consumer can consume.)

Thanks!
Brian



More information about the Libc-alpha mailing list