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;
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)
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) {
102 std::atomic<Int64> m_count = 0;
105 Int32 m_nb_sub_iter = 1000;
116 : m_thread_implementation(Concurrency::getThreadImplementation())
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;
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);
147 for (
Int32 i = 0; i < m_nb_sub_iter; ++i) {
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();
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++.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Functor associé à une méthode d'une classe T.
Interface d'une barrière entre threads.
virtual void destroy()=0
Détruit la barrière.
virtual bool wait()=0
Bloque et attend que tous les threads appellent cette méthode.
virtual void init(Integer nb_thread)=0
Initialise la barrière pour nb_thread.
Interface d'un service implémentant le support des threads.
Référence à une instance.
eMode
Mode du spinlock. Le défaut est 'Auto'.
Espace de nom de Arccore.
Int32 Integer
Type représentant un entier.
std::int64_t Int64
Type entier signé sur 64 bits.
std::int32_t Int32
Type entier signé sur 32 bits.