mardi 7 septembre 2021

c++ folly:::LifoSem do no syn atomic value when post

#include "folly/synchronization/LifoSem.h"
#include <iostream>
#include <atomic>
#include "gtest/gtest.h"

TEST(lifo, atomic)
{
  std::atomic<int> a_i{0};
  folly::LifoSem sem_;
  std::thread t1([&]()
                 {
                   for(int i = 0; i < 10; i++)
                   {
                     a_i++;
                     sem_.post();
                   }
                 });
  std::thread t2([&]()
                 {
                   for(int i = 0; i < 10; i++)
                   {
                     sem_.wait();
                     int v = a_i.load();
                     EXPECT_TRUE(v > i+1);
                     }
                 });
  t1.join();
  t2.join();
}

The UT could not pass. when folly::LifoSem post a signal , one thread receive the signal, but it could not read the value the poster write.

Aucun commentaire:

Enregistrer un commentaire