Scheduling algorithms by thread, why delay(1) ?

Hi Thank You !!!

Scheduling algorithms by thread, why delay(1) for periodic result?

When scheduling is done by thread, and the default scheduling for both thread’d is round-robin by Prio 10, and Every thread consumed its timeslice after 4 ms , why I get this non periodic result?

e.g.

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX__________
______________XXXXXXXXXXXXXXXXXXXXXXXX
__XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX_XXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

and not this:
X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X
X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X
X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X
X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X
X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X_X

or not this:
XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX______
XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX______
XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX______
XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX______
XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX_____XXXXX______

Why I have to work with “delay(1)â€

because printf() causes rescheduling

Thank you mezek,

you mean “pritf()” starts the scheduler again, so he can’t stop after consumed its timeslice ?

And what causes “delay(1)” why Threads need a delay of 1ms?

pleas explain me exactly.

Thank You!!!

  • printf causes rescheduling and rescheduling causes reset of the timeslice of the thread to its initial value
  • well, delay(1) also causes rescheduling (current running thread is going to a blocked state and another thread will be scheduled to run)

i do not think that you can create an example on round robin timeslice using printf() and delay() in the “worker threads”

well for one thing printf is line buffered by default
but as noted, io will actually cause a context switch to another process