7#include <gtest/gtest.h> 
    9#include "arccore/base/PlatformUtils.h" 
   10#include "arccore/base/Functor.h" 
   13#include "arccore/concurrency/SpinLock.h" 
   14#include "arccore/concurrency/Mutex.h" 
   15#include "arccore/concurrency/IThreadBarrier.h" 
   34      Concurrency::getThreadImplementation()->destroyThread(m_thread);
 
   39    m_thread = Concurrency::getThreadImplementation()->createThread(f);
 
   43    Concurrency::getThreadImplementation()->joinThread(m_thread);
 
   49  ThreadImpl* m_thread = 
nullptr;
 
 
   63  explicit TestSpinLock1(SpinLock::eMode mode)
 
   70    Real v1 = Platform::getRealTime();
 
   71    const Int32 nb_iter = 70;
 
   72    const Int32 nb_thread = 10;
 
   73    for (
Integer i = 0; i < nb_iter; ++i) {
 
   75      std::vector<MyThread> threads(nb_thread);
 
   76      for (
Integer j = 0; j < nb_thread; ++j)
 
   77        threads[j].create(&f1);
 
   78      for (
Integer j = 0; j < nb_thread; ++j)
 
   81    Real v2 = Platform::getRealTime();
 
   82    std::cout << 
"Test1 spin_time=" << (v2 - v1) << 
" count2=" << m_count2 << 
" count3=" << m_count3 << 
"\n";
 
   83    Int64 expected_count3 = nb_iter * m_nb_sub_iter * nb_thread;
 
   84    Int64 expected_count2 = 10 * expected_count3 + (expected_count3 * (expected_count3 + 1)) / 2;
 
   85    std::cout << 
" expected_count2=" << expected_count2 << 
" expected_count3=" << expected_count3 << 
"\n";
 
   86    ASSERT_EQ(m_count2, expected_count2);
 
   87    ASSERT_EQ(m_count3, expected_count3);
 
   91    for (Int32 i = 0; i < m_nb_sub_iter; ++i) {
 
   94        SpinLock::ScopedLock sl(m_lock);
 
  102  std::atomic<Int64> m_count = 0;
 
  105  Int32 m_nb_sub_iter = 1000;
 
 
  116  : m_thread_implementation(Concurrency::getThreadImplementation())
 
  122    Real v1 = Platform::getRealTime();
 
  123    const Int32 nb_iter = 70;
 
  124    const Int32 nb_thread = 10;
 
  125    m_thread_barrier = m_thread_implementation->createBarrier();
 
  126    m_thread_barrier->init(nb_thread);
 
  127    for (
Integer i = 0; i < nb_iter; ++i) {
 
  129      std::vector<MyThread> threads(nb_thread);
 
  130      for (
Integer j = 0; j < nb_thread; ++j)
 
  131        threads[j].create(&f1);
 
  132      for (
Integer j = 0; j < nb_thread; ++j)
 
  134      m_do_print_id = 
false;
 
  136    Real v2 = Platform::getRealTime();
 
  137    std::cout << 
"Test1 spin_time=" << (v2 - v1) << 
" count2=" << m_count2 << 
" count3=" << m_count3 << 
"\n";
 
  138    Int64 expected_count3 = nb_iter * m_nb_sub_iter * nb_thread;
 
  139    Int64 expected_count2 = 10 * expected_count3 + (expected_count3 * (expected_count3 + 1)) / 2;
 
  140    std::cout << 
" expected_count2=" << expected_count2 << 
" expected_count3=" << expected_count3 << 
"\n";
 
  141    ASSERT_EQ(m_count2, expected_count2);
 
  142    ASSERT_EQ(m_count3, expected_count3);
 
  143    m_thread_barrier->destroy();
 
  147    for (Int32 i = 0; i < m_nb_sub_iter; ++i) {
 
  150        Mutex::ScopedLock sl(m_mutex);
 
  153        m_count2 += m_count3;
 
  156    m_thread_barrier->wait();
 
  158      std::ostringstream ostr;
 
  159      ostr << 
"THREAD_ID=" << m_thread_implementation->currentThread() << 
"\n";
 
  160      std::cout << ostr.str();
 
  163  IThreadImplementation* m_thread_implementation = 
nullptr;
 
  165  IThreadBarrier* m_thread_barrier = 
nullptr;
 
  166  std::atomic<Int64> m_count = 0;
 
  169  Int32 m_nb_sub_iter = 1000;
 
  170  bool m_do_print_id = 
true;
 
 
  201TEST(Concurrency, GlibSpinLock)
 
  204  Concurrency::setThreadImplementation(timpl.get());
 
  206  Concurrency::setThreadImplementation(
nullptr);
 
  209TEST(Concurrency, StdSpinLock)
 
  212  Concurrency::setThreadImplementation(timpl.get());
 
  214  Concurrency::setThreadImplementation(
nullptr);
 
  217TEST(Concurrency, GlibMutexLock)
 
  220  Concurrency::setThreadImplementation(timpl.get());
 
  222  Concurrency::setThreadImplementation(
nullptr);
 
  225TEST(Concurrency, StdMutexLock)
 
  228  Concurrency::setThreadImplementation(timpl.get());
 
  230  Concurrency::setThreadImplementation(
nullptr);
 
Gestion des références à une classe C++.
 
Functor associé à une méthode d'une classe T.
 
Référence à une instance.
 
Int32 Integer
Type représentant un entier.
 
double Real
Type représentant un réel.
 
Espace de nom de Arccore.