Advertisement
orenty7

Untitled

Feb 23rd, 2024
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.08 KB | None | 0 0
  1.   SIMPLE_TEST(FutexCountAfterHeavyRound) {
  2.     twist::sim::sched::FairScheduler scheduler;
  3.     twist::sim::Simulator simulator{&scheduler};
  4.  
  5.     auto result = simulator.Run([&] {
  6.       WaitGroup wg;
  7.  
  8.       static const size_t kWork = 64;
  9.  
  10.       // Round 1
  11.       for (size_t i = 0; i < kWork; ++i) {
  12.         wg.Add(1);
  13.       }
  14.  
  15.       // Forcing waitgroup to set internal <need to wake> flag
  16.       twist::ed::std::thread t([&] {
  17.         wg.Wait();
  18.       });
  19.  
  20.       for (size_t i = 0; i < kWork; ++i) {
  21.         wg.Done();
  22.       }
  23.  
  24.       wg.Wait();
  25.       t.join();
  26.  
  27.       const auto after_first_round = simulator.FutexCount();
  28.  
  29.       // Round 2 (flag must be reset, but it isn't)
  30.       for (size_t i = 0; i < kWork; ++i) {
  31.         wg.Add(1);
  32.       }
  33.  
  34.       for (size_t i = 0; i < kWork; ++i) {
  35.         wg.Done();
  36.       }
  37.  
  38.       wg.Wait();
  39.  
  40.       const auto after_second_round = simulator.FutexCount();
  41.       const auto second_round_only = after_second_round - after_first_round;
  42.  
  43.       ASSERT_EQ(second_round_only, 0);
  44.     });
  45.  
  46.     ASSERT_TRUE(result.Ok());
  47.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement