I have 50 threads, each of which I want to run a SEGMENT of code, approximately 'fairly', every 200 milli seconds.
Here, 'fairly' means: at any given time, there exists some k, where for each SEGMENT, it has been executed for >= k, <= k+1 times.
One obvious way to do this is to setup each thread as:
worker thread_i
loop {
acquire semaphore_i;
SEGMENT
}
control thread:
loop {
for all i: release semahore_i;
sleep for 200 millis
}
===
assume that all tasks complete in 200 millis
===
question: are there other approaches worth considering ?