The ROme OpTimistic Simulator
3.0.0
A General-Purpose Multithreaded Parallel/Distributed Simulation Platform
sync_test.c
Go to the documentation of this file.
1
10
#include <
test.h
>
11
12
#include <
core/core.h
>
13
#include <
core/sync.h
>
14
15
#include <stdatomic.h>
16
17
static
atomic_uint counter;
18
19
#define THREAD_CNT 2
20
21
static
int
sync_test(
void
)
22
{
23
int
ret = 0;
24
unsigned
i = THREAD_CNT * 100000;
25
while
(i--){
26
atomic_fetch_add_explicit(&counter, 1U, memory_order_relaxed);
27
sync_thread_barrier
();
28
unsigned
val = atomic_load_explicit(&counter, memory_order_relaxed);
29
sync_thread_barrier
();
30
ret -= val % THREAD_CNT;
31
}
32
return
ret;
33
}
34
35
const
struct
test_config
test_config
= {
36
.
threads_count
= THREAD_CNT,
37
.test_fnc = sync_test,
38
};
sync.h
Easier Synchronization primitives.
test_config
A complete test configuration.
Definition:
test.h:22
sync_thread_barrier
bool sync_thread_barrier(void)
Synchronizes threads on a barrier.
Definition:
sync.c:19
test.h
Test framework header.
core.h
Core ROOT-Sim functionalities.
test_config::threads_count
unsigned threads_count
test_fnc is executed with that many cores
Definition:
test.h:33
test
core
sync_test.c
Generated by
1.8.17