aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/threading/future/subscription/wait_ut_common.cpp
blob: 35a6121bb91b2edaaa6dd5f116355eb180f97a3e (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(); 
} 
 
}