File tree Expand file tree Collapse file tree 2 files changed +34
-2
lines changed
cloud/storage/core/libs/common Expand file tree Collapse file tree 2 files changed +34
-2
lines changed Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ class TThreadPool final
8888 worker.Name = TStringBuilder () << threadName << i++;
8989 worker.Thread = std::make_unique<TWorkerThread>(*this , worker);
9090 }
91+ AtomicSet (RunningWorkers, NumWorkers);
9192 }
9293
9394 ~TThreadPool () override
@@ -97,8 +98,6 @@ class TThreadPool final
9798
9899 void Start () override
99100 {
100- AtomicSet (RunningWorkers, NumWorkers);
101-
102101 for (auto & worker: Workers) {
103102 worker.Thread ->Start ();
104103 }
Original file line number Diff line number Diff line change 66
77#include < util/generic/scope.h>
88
9+ #include < thread>
10+
911namespace NCloud {
1012
1113// //////////////////////////////////////////////////////////////////////////////
@@ -30,6 +32,37 @@ Y_UNIT_TEST_SUITE(TThreadPoolTest)
3032
3133 UNIT_ASSERT_EQUAL (future.GetValue (WaitTimeout), 42 );
3234 }
35+
36+ Y_UNIT_TEST (ShouldExecuteTaskEnqueuedBeforeStart)
37+ {
38+ auto threadPool = CreateThreadPool (" thread" , 1 );
39+
40+ auto promise = NThreading::NewPromise ();
41+
42+ auto future = promise.GetFuture ();
43+
44+ std::thread thread (
45+ [threadPool, promise = std::move (promise)]() mutable
46+ {
47+ promise.SetValue ();
48+ auto future = threadPool->Execute ([] { return 42 ; });
49+
50+ UNIT_ASSERT_EQUAL (future.GetValue (WaitTimeout), 42 );
51+ });
52+
53+ future.GetValueSync ();
54+
55+ // Sleep to be sure that task will be enqueued before start.
56+ Sleep (TDuration::Seconds (1 ));
57+
58+ threadPool->Start ();
59+ Y_DEFER
60+ {
61+ threadPool->Stop ();
62+ };
63+
64+ thread.join ();
65+ }
3366}
3467
3568// //////////////////////////////////////////////////////////////////////////////
You can’t perform that action at this time.
0 commit comments