7#include <gtest/gtest.h>
9#include "arccore/base/PlatformUtils.h"
10#include "arccore/base/Functor.h"
13#include "arccore/concurrency/internal/ConcurrencyGlobalInternal.h"
14#include "arccore/concurrency/SpinLock.h"
15#include "arccore/concurrency/Mutex.h"
16#include "arccore/concurrency/IThreadBarrier.h"
35 Concurrency::getThreadImplementation()->destroyThread(m_thread);
40 m_thread = Concurrency::getThreadImplementation()->createThread(f);
44 Concurrency::getThreadImplementation()->joinThread(m_thread);
50 ThreadImpl* m_thread =
nullptr;
72 const Int32 nb_iter = 70;
73 const Int32 nb_thread = 10;
74 for (
Integer i = 0; i < nb_iter; ++i) {
76 std::vector<MyThread> threads(nb_thread);
77 for (
Integer j = 0; j < nb_thread; ++j)
78 threads[j].create(&f1);
79 for (
Integer j = 0; j < nb_thread; ++j)
83 std::cout <<
"Test1 spin_time=" << (v2 - v1) <<
" count2=" << m_count2 <<
" count3=" << m_count3 <<
"\n";
84 Int64 expected_count3 = nb_iter * m_nb_sub_iter * nb_thread;
85 Int64 expected_count2 = 10 * expected_count3 + (expected_count3 * (expected_count3 + 1)) / 2;
86 std::cout <<
" expected_count2=" << expected_count2 <<
" expected_count3=" << expected_count3 <<
"\n";
87 ASSERT_EQ(m_count2, expected_count2);
88 ASSERT_EQ(m_count3, expected_count3);
92 for (
Int32 i = 0; i < m_nb_sub_iter; ++i) {
103 std::atomic<Int64> m_count = 0;
106 Int32 m_nb_sub_iter = 1000;
117 : m_thread_implementation(Concurrency::getThreadImplementation())
124 const Int32 nb_iter = 70;
125 const Int32 nb_thread = 10;
126 m_thread_barrier = m_thread_implementation->createBarrier();
127 m_thread_barrier->init(nb_thread);
128 for (
Integer i = 0; i < nb_iter; ++i) {
130 std::vector<MyThread> threads(nb_thread);
131 for (
Integer j = 0; j < nb_thread; ++j)
132 threads[j].create(&f1);
133 for (
Integer j = 0; j < nb_thread; ++j)
135 m_do_print_id =
false;
138 Int64 nb_sub_iter = m_nb_sub_iter;
139 std::cout <<
"Test1 spin_time=" << (v2 - v1) <<
" count2=" << m_count2 <<
" count3=" << m_count3 <<
"\n";
140 Int64 i64_nb_thread = nb_thread;
141 Int64 expected_count3 = nb_iter * nb_sub_iter * i64_nb_thread;
142 Int64 expected_count2 = 10 * expected_count3 + (expected_count3 * (expected_count3 + 1)) / 2;
143 std::cout <<
" expected_count2=" << expected_count2 <<
" expected_count3=" << expected_count3 <<
"\n";
144 ASSERT_EQ(m_count2, expected_count2);
145 ASSERT_EQ(m_count3, expected_count3);
146 m_thread_barrier->destroy();
150 for (
Int32 i = 0; i < m_nb_sub_iter; ++i) {
156 m_count2 += m_count3;
159 m_thread_barrier->wait();
161 std::ostringstream ostr;
162 ostr <<
"THREAD_ID=" << m_thread_implementation->currentThread() <<
"\n";
163 std::cout << ostr.str();
169 std::atomic<Int64> m_count = 0;
172 Int32 m_nb_sub_iter = 1000;
173 bool m_do_print_id =
true;
204TEST(Concurrency, GlibSpinLock)
207 Concurrency::setThreadImplementation(timpl.get());
209 Concurrency::setThreadImplementation(
nullptr);
212TEST(Concurrency, StdSpinLock)
215 Concurrency::setThreadImplementation(timpl.get());
217 Concurrency::setThreadImplementation(
nullptr);
220TEST(Concurrency, GlibMutexLock)
223 Concurrency::setThreadImplementation(timpl.get());
225 Concurrency::setThreadImplementation(
nullptr);
228TEST(Concurrency, StdMutexLock)
231 Concurrency::setThreadImplementation(timpl.get());
233 Concurrency::setThreadImplementation(
nullptr);
236TEST(Concurrency, LegacyStdMutexLock)
239 Concurrency::setThreadImplementation(timpl.get());
241 Concurrency::setThreadImplementation(
nullptr);
Gestion des références à une classe C++.
Functor associé à une méthode d'une classe T.
Interface d'une barrière entre threads.
Interface d'un service implémentant le support des threads.
Référence à une instance.
eMode
Mode du spinlock. Le défaut est 'Auto'.
@ SpinAndMutex
SpinLock puis mutex.
@ FullSpin
Utilise toujours un spinlock.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::int64_t Int64
Type entier signé sur 64 bits.
Int32 Integer
Type représentant un entier.
double Real
Type représentant un réel.
std::int32_t Int32
Type entier signé sur 32 bits.