aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/multithreaded_volatile
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2020-03-03 08:17:40 +0100
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2020-03-03 08:17:40 +0100
commit1ab7b51c30e1b10ac45b0bd64cefdc01da0f7f68 (patch)
tree210ffc156c83f04fb0c61a40b4f9037d7ba8a7e1 /test/monniaux/multithreaded_volatile
parent222c9047d61961db9c6b19fed5ca49829223fd33 (diff)
parent12be46d59a2483a10d77fa8ee67f7e0ca1bd702f (diff)
downloadcompcert-kvx-1ab7b51c30e1b10ac45b0bd64cefdc01da0f7f68.tar.gz
compcert-kvx-1ab7b51c30e1b10ac45b0bd64cefdc01da0f7f68.zip
Merge branch 'mppa-cse2' of gricad-gitlab.univ-grenoble-alpes.fr:sixcy/CompCert into mppa-work
Diffstat (limited to 'test/monniaux/multithreaded_volatile')
-rw-r--r--test/monniaux/multithreaded_volatile/Makefile18
-rw-r--r--test/monniaux/multithreaded_volatile/volatile.c30
2 files changed, 48 insertions, 0 deletions
diff --git a/test/monniaux/multithreaded_volatile/Makefile b/test/monniaux/multithreaded_volatile/Makefile
new file mode 100644
index 00000000..35717953
--- /dev/null
+++ b/test/monniaux/multithreaded_volatile/Makefile
@@ -0,0 +1,18 @@
+all: volatile.ccomp.k1c volatile.gcc.k1c
+
+volatile.ccomp.k1c : volatile.ccomp.k1c.s
+ k1-cos-gcc $< -o $@
+
+volatile.gcc.k1c : volatile.gcc.k1c.s
+ k1-cos-gcc $< -o $@
+
+volatile.ccomp.k1c.s : volatile.c
+ ../../../ccomp -O2 -Wall -S $< -o $@
+
+volatile.gcc.k1c.s : volatile.c
+ k1-cos-gcc -O2 -Wall -Werror=implicit -std=gnu99 -S $< -o $@
+
+clean:
+ -rm -f *.k1c *.s
+
+.PHONY: clean
diff --git a/test/monniaux/multithreaded_volatile/volatile.c b/test/monniaux/multithreaded_volatile/volatile.c
new file mode 100644
index 00000000..f8ffee2d
--- /dev/null
+++ b/test/monniaux/multithreaded_volatile/volatile.c
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <time.h>
+#include <pthread.h>
+
+typedef unsigned data;
+
+static inline data powM(data x, unsigned e) {
+ data y = 1;
+ for(unsigned i=0; i<e; i++) {
+ y = (y * x) % 65537;
+ }
+ return y;
+}
+
+void* second_thread_entry(void *ptr) {
+ *((volatile data*) ptr) = powM(3, 65536);
+ return NULL;
+}
+
+int main() {
+ pthread_t second_thread_id;
+ volatile data value;
+ pthread_create(&second_thread_id, NULL,
+ second_thread_entry, (void*) &value);
+ value = 69;
+ data correct = powM(3, 65536*2);
+ data read = value;
+ pthread_join(second_thread_id, NULL);
+ printf("%u %u %s\n", read, correct, read == correct ? "OK" : "FAIL");
+}