aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/volatile
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-09 19:16:01 +0100
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-09 19:16:01 +0100
commit3e40a17befddbdf9f96d7f7299d31f88376093dc (patch)
treeb445874d62e74f32d47f315df424bad2ebc80862 /test/monniaux/volatile
parentea961fe2f20f88bbea547e23104c026f14e4ebc6 (diff)
downloadcompcert-kvx-3e40a17befddbdf9f96d7f7299d31f88376093dc.tar.gz
compcert-kvx-3e40a17befddbdf9f96d7f7299d31f88376093dc.zip
program for testing volatiles
Diffstat (limited to 'test/monniaux/volatile')
-rw-r--r--test/monniaux/volatile/volatile.c32
1 files changed, 32 insertions, 0 deletions
diff --git a/test/monniaux/volatile/volatile.c b/test/monniaux/volatile/volatile.c
new file mode 100644
index 00000000..75f8ce3b
--- /dev/null
+++ b/test/monniaux/volatile/volatile.c
@@ -0,0 +1,32 @@
+#include <pthread.h>
+#include <stdio.h>
+#include <time.h>
+
+#define VOLATILE volatile
+
+typedef unsigned data;
+
+static data powm(data x, unsigned e, data m) {
+ data y = 1;
+ for(unsigned i=0; i<e; i++) {
+ y = (y * x) % m;
+ }
+ return y;
+}
+
+void* second_thread_entry(void *ptr) {
+ *((data*) ptr) = powm(3, 65536, 65537);
+ return NULL;
+}
+
+int main() {
+ pthread_t second_thread_id;
+ VOLATILE data value;
+ pthread_create(&second_thread_id, NULL,
+ second_thread_entry, (void*) &value);
+ value = 0;
+ data correct = powm(3, 65536*4, 65537);;
+ data read = value;
+ pthread_join(second_thread_id, NULL);
+ printf("%u %u\n", correct, read);
+}