Rate-limit the number of threads copying closures at the same time

Having a hundred threads doing I/O at the same time is bad on magnetic
disks because of the excessive disk seeks. So allow only 4 threads to
copy closures in parallel.
This commit is contained in:
Eelco Dolstra
2015-06-23 01:49:14 +02:00
parent a317d24b29
commit 4db7c51b5c
5 changed files with 106 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
#include <mutex>
#include <condition_variable>
#include <cassert>
/* This template class ensures synchronized access to a value of type
T. It is used as follows:
@@ -50,6 +51,15 @@ public:
assert(s);
cv.wait(s->mutex);
}
template<class Rep, class Period, class Predicate>
bool wait_for(std::condition_variable_any & cv,
const std::chrono::duration<Rep, Period> & duration,
Predicate pred)
{
assert(s);
return cv.wait_for(s->mutex, duration, pred);
}
};
Lock lock() { return Lock(this); }