|
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 |
|
17 | | -#include <folly/CPortability.h> |
18 | | -#include <folly/DefaultKeepAliveExecutor.h> |
19 | | -#include <folly/executors/CPUThreadPoolExecutor.h> |
20 | | -#include <folly/executors/ThreadPoolExecutor.h> |
21 | | -#include <folly/lang/Keep.h> |
22 | | -#include <folly/synchronization/Latch.h> |
23 | | - |
24 | 17 | #include <atomic> |
25 | 18 | #include <memory> |
26 | 19 | #include <thread> |
27 | 20 |
|
28 | 21 | #include <boost/thread.hpp> |
29 | | - |
| 22 | +#include <folly/CPortability.h> |
| 23 | +#include <folly/DefaultKeepAliveExecutor.h> |
30 | 24 | #include <folly/Exception.h> |
31 | 25 | #include <folly/container/F14Map.h> |
| 26 | +#include <folly/executors/CPUThreadPoolExecutor.h> |
32 | 27 | #include <folly/executors/EDFThreadPoolExecutor.h> |
33 | 28 | #include <folly/executors/FutureExecutor.h> |
34 | 29 | #include <folly/executors/IOThreadPoolExecutor.h> |
| 30 | +#include <folly/executors/ThreadPoolExecutor.h> |
35 | 31 | #include <folly/executors/VirtualExecutor.h> |
36 | 32 | #include <folly/executors/task_queue/LifoSemMPMCQueue.h> |
37 | 33 | #include <folly/executors/task_queue/UnboundedBlockingQueue.h> |
38 | 34 | #include <folly/executors/thread_factory/InitThreadFactory.h> |
39 | 35 | #include <folly/executors/thread_factory/PriorityThreadFactory.h> |
| 36 | +#include <folly/lang/Keep.h> |
40 | 37 | #include <folly/portability/GMock.h> |
41 | 38 | #include <folly/portability/GTest.h> |
42 | 39 | #include <folly/portability/PThread.h> |
43 | 40 | #include <folly/portability/SysResource.h> |
| 41 | +#include <folly/synchronization/Latch.h> |
44 | 42 | #include <folly/synchronization/detail/Spin.h> |
45 | 43 | #include <folly/system/ThreadId.h> |
46 | 44 |
|
@@ -626,6 +624,29 @@ TEST(ThreadPoolExecutorTest, BlockingQueue) { |
626 | 624 | EXPECT_EQ(5, c); |
627 | 625 | } |
628 | 626 |
|
| 627 | +TEST(ThreadPoolExecutorTest, NoThreadPriorityInheritance) { |
| 628 | + constexpr size_t kNumThreads = 16; |
| 629 | + const auto initialPriority = getpriority(PRIO_PROCESS, 0); |
| 630 | + |
| 631 | + // If minThreads == maxThreads, no threads should be created on add(), and |
| 632 | + // thus they should not inherit the parent thread's priority. Instead, all |
| 633 | + // threads should inherit the priority at the time of construction. |
| 634 | + CPUThreadPoolExecutor exe{std::make_pair(kNumThreads, kNumThreads)}; |
| 635 | + |
| 636 | + // Nice the current thread. |
| 637 | + setpriority(PRIO_PROCESS, 0, 19); |
| 638 | + |
| 639 | + Latch ready{kNumThreads + 1}; |
| 640 | + for (size_t i = 0; i < kNumThreads; ++i) { |
| 641 | + exe.add([&] { |
| 642 | + EXPECT_EQ(getpriority(PRIO_PROCESS, 0), initialPriority); |
| 643 | + ready.arrive_and_wait(); |
| 644 | + }); |
| 645 | + } |
| 646 | + ready.arrive_and_wait(); |
| 647 | + exe.join(); |
| 648 | +} |
| 649 | + |
629 | 650 | TEST(PriorityThreadFactoryTest, ThreadPriority) { |
630 | 651 | errno = 0; |
631 | 652 | auto currentPriority = getpriority(PRIO_PROCESS, 0); |
|
0 commit comments