blob: 9f961e73036838d529f5c4548796d6dfbcd0d092 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include "wait_ut_common.h"
#include <util/random/shuffle.h>
#include <util/system/event.h>
#include <util/thread/pool.h>
namespace NThreading::NTest::NPrivate {
void ExecuteAndWait(TVector<std::function<void()>> jobs, TFuture<void> waiter, size_t threads) {
Y_ENSURE(threads > 0);
Shuffle(jobs.begin(), jobs.end());
auto pool = CreateThreadPool(threads);
TManualEvent start;
for (auto& j : jobs) {
pool->SafeAddFunc(
[&start, job = std::move(j)]() {
start.WaitI();
job();
});
}
start.Signal();
waiter.Wait();
pool->Stop();
}
}
|