blob: 91867ba46a024b61399c1fe4e5f07a152ea2d011 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/* { dg-do link } */
/* { dg-options "-std=c++0x" } */
/* { dg-final { simulate-thread } } */
/* { dg-require-effective-target sync_char_short } */
/* { dg-require-effective-target sync_int_long } */
/* Test that atomic int and atomic char work properly. */
using namespace std;
#include <atomic>
#include <limits.h>
#include <stdio.h>
#include "simulate-thread.h"
atomic<int> atomi;
atomic<char> atomc;
/* No need for parallel threads to do anything */
void simulate_thread_other_threads()
{
}
/* Verify after every instruction is executed, that the atmoic int and
char have one of the 2 legitimate values. */
int simulate_thread_step_verify()
{
if (atomi != 0 && atomi != INT_MAX)
{
printf ("FAIL: invalid intermediate result for atomi (%d).\n",
(int)atomi);
return 1;
}
if (atomc != 0 && atomc != CHAR_MAX)
{
printf ("FAIL: invalid intermediate result for atomc (%d).\n",
(int)atomc);
return 1;
}
return 0;
}
/* Verify that both atmoics have the corerct value. */
int simulate_thread_final_verify()
{
if (atomi != INT_MAX)
{
printf ("FAIL: invalid final result for atomi (%d).\n",
(int)atomi);
return 1;
}
if (atomc != CHAR_MAX)
{
printf ("FAIL: invalid final result for atomc (%d).\n",
(int)atomc);
return 1;
}
return 0;
}
/* Test a store to an atomic int and an atomic char. */
__attribute__((noinline))
void simulate_thread_main()
{
atomi = INT_MAX;
atomc = CHAR_MAX;
}
int main ()
{
simulate_thread_main();
simulate_thread_done();
return 0;
}
|