Testing Continue/Suspend API.
442 {
443
445
446 m_ThreadPool.Suspend();
447
448 std::atomic_int executeCount;
449
450 {
452
453 for (int i = 0; i < 10; i++)
454 {
455 m_ThreadPool.SubmitPoolTask([&]() {
456 ++executeCount;
457 });
458 }
459
460 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), 10);
461 EXPECT_EQ(m_ThreadPool.GetTasks(), 10);
462
463 m_ThreadPool.Continue();
464
465 m_ThreadPool.Wait();
466 m_ThreadPool.Suspend();
467
468 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), 10);
469 EXPECT_EQ(m_ThreadPool.GetTasks(), 0);
470 EXPECT_EQ(executeCount.load(), 10);
471 }
472
473 {
475
476 for (int i = 0; i < 10; i++)
477 {
478 m_ThreadPool.SubmitPoolTask([&]() {
479 std::this_thread::sleep_for(std::chrono::seconds(2));
480 ++executeCount;
481 });
482 }
483
484 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), 10);
485 EXPECT_EQ(m_ThreadPool.GetTasks(), 10);
486
487 m_ThreadPool.Continue();
488 std::this_thread::sleep_for(std::chrono::seconds(1));
489 m_ThreadPool.Suspend();
490 std::this_thread::sleep_for(std::chrono::seconds(2));
491
492 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), 10);
493 EXPECT_EQ(m_ThreadPool.GetTasks(), 0);
494 EXPECT_EQ(executeCount.load(), 20);
495
496 m_ThreadPool.Continue();
497 m_ThreadPool.Wait();
498
499 EXPECT_EQ(m_ThreadPool.GetIdleThreadSize(), 10);
500 EXPECT_EQ(m_ThreadPool.GetTasks(), 0);
501 EXPECT_EQ(executeCount.load(), 20);
502 }
503 }
#define SPICESTEST_PROFILE_SCOPE(name)
#define SPICESTEST_PROFILE_FUNCTION()