| 83 | } |
| 84 | |
| 85 | void SC::ThreadPoolTest::testThreadPoolErrors() |
| 86 | { |
| 87 | static const size_t numTasks = 4; |
| 88 | |
| 89 | // Define tasks before threadpool to avoid threadpool destructor accessing invalid tasks |
| 90 | SC::ThreadPool::Task tasks[numTasks]; |
| 91 | |
| 92 | SC::ThreadPool threadPool; |
| 93 | SC_TEST_EXPECT(threadPool.create(2)); |
| 94 | SC::ThreadPool threadPool2; |
| 95 | SC_TEST_EXPECT(threadPool2.create(1)); |
| 96 | |
| 97 | for (size_t idx = 0; idx < numTasks; idx++) |
| 98 | { |
| 99 | |
| 100 | tasks[idx].function = []() { SC::Thread::Sleep(100); }; |
| 101 | SC_TEST_EXPECT(threadPool.queueTask(tasks[idx])); |
| 102 | } |
| 103 | // Expect error if trying to add a task to another threadpool |
| 104 | SC_TEST_EXPECT(not threadPool2.queueTask(tasks[1])); |
| 105 | // Expect error if trying to queue a task again |
| 106 | SC_TEST_EXPECT(not threadPool.queueTask(tasks[1])); |
| 107 | } |
| 108 | |
| 109 | namespace SC |
| 110 | { |