1
0
mirror of https://github.com/zenorogue/hyperrogue.git synced 2024-11-23 21:07:17 +00:00

restructure scheduling intervals

so that there is just one pause for every sweep of the workforce,
so that upper bound on idle time doesn't grow
proportionally to the number of workers
This commit is contained in:
still-flow 2020-05-30 17:17:51 +03:00
parent d6de73a1dc
commit 31d836b2a9

View File

@ -11,6 +11,7 @@
#include <string> #include <string>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <thread>
#include <vector> #include <vector>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
@ -239,17 +240,17 @@ int main(int argc, char **argv) {
id++; id++;
} }
chrono::milliseconds quantum(25); chrono::milliseconds quantum(40);
vector<future<int>> workers(batch_size); vector<future<int>> workers(batch_size);
int tasks_amt = tasks.size(); int tasks_amt = tasks.size();
int tasks_taken = 0, tasks_done = 0; int tasks_taken = 0, tasks_done = 0;
bool finished = tasks.empty(); bool finished = tasks.empty();
while (!finished) while (!finished) {
for (auto & worker : workers) { for (auto & worker : workers) {
if (worker.valid()) { if (worker.valid()) {
if (worker.wait_for(quantum) != future_status::ready) continue; if (worker.wait_for(chrono::seconds(0)) != future_status::ready) continue;
else { else {
int res = worker.get(); int res = worker.get();
if (res) { printf("compilation error!\n"); exit(1); } if (res) { printf("compilation error!\n"); exit(1); }
@ -265,7 +266,7 @@ int main(int argc, char **argv) {
++tasks_taken; ++tasks_taken;
} }
else if (tasks_done == tasks_amt) { finished = true; break; } else if (tasks_done == tasks_amt) { finished = true; break; }
} } this_thread::sleep_for(quantum); }
printf("linking...\n"); printf("linking...\n");
system(linker + allobj + libs); system(linker + allobj + libs);