@@ -148,9 +148,9 @@ TEST(ChannelTest, Iterator)
148148
149149TEST (ChannelTest, Multithreading)
150150{
151- const int numbers = 10000 ;
152- const std::int64_t expected = 50005000 ;
153- constexpr std::size_t kThreadsToReadFrom = 100 ;
151+ const int numbers = 1000 ;
152+ const std::int64_t expected = 500500 ;
153+ constexpr std::size_t kThreadsToReadFrom = 50 ;
154154
155155 msd::channel<int > channel{10 };
156156
@@ -176,6 +176,8 @@ TEST(ChannelTest, Multithreading)
176176
177177 sum_numbers += out;
178178 ++count_numbers;
179+
180+ std::this_thread::sleep_for (std::chrono::milliseconds (1 ));
179181 }
180182 --wait_counter;
181183 cond_wait.notify_one ();
@@ -186,16 +188,19 @@ TEST(ChannelTest, Multithreading)
186188 threads.emplace_back (std::thread{worker});
187189 }
188190
189- // Send numbers to channel
190- for (int i = 1 ; i <= numbers; ++i) {
191- channel << i;
191+ auto sender = [&] {
192+ // Send numbers to channel
193+ for (int i = 1 ; i <= numbers; ++i) {
194+ channel << i;
192195
193- // Notify threads than then can start reading
194- if (!ready_to_read) {
195- ready_to_read = true ;
196- cond_read.notify_all ();
196+ // Notify threads than then can start reading
197+ if (!ready_to_read) {
198+ ready_to_read = true ;
199+ cond_read.notify_all ();
200+ }
197201 }
198- }
202+ };
203+ threads.emplace_back (std::thread{sender});
199204
200205 // Wait until all items have been read
201206 std::unique_lock<std::mutex> lock{mtx_wait};
0 commit comments