aboutsummaryrefslogtreecommitdiffstats
path: root/test/monniaux/multithreaded_volatile
diff options
context:
space:
mode:
authorDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-11 21:18:58 +0100
committerDavid Monniaux <david.monniaux@univ-grenoble-alpes.fr>2019-03-11 21:18:58 +0100
commit075b632376b95ccc8874a0496a2b25b740820084 (patch)
tree292186fdb21a85da786661a99a5cfdae47e020c9 /test/monniaux/multithreaded_volatile
parente5c1fcd887f571f54c54be5a0555902804d2983d (diff)
downloadcompcert-kvx-075b632376b95ccc8874a0496a2b25b740820084.tar.gz
compcert-kvx-075b632376b95ccc8874a0496a2b25b740820084.zip
wrong directory, fixed
Diffstat (limited to 'test/monniaux/multithreaded_volatile')
-rw-r--r--test/monniaux/multithreaded_volatile/volatile.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/monniaux/multithreaded_volatile/volatile.c b/test/monniaux/multithreaded_volatile/volatile.c
new file mode 100644
index 00000000..d4e08d6d
--- /dev/null
+++ b/test/monniaux/multithreaded_volatile/volatile.c
@@ -0,0 +1,33 @@
+#include <stdio.h>
+#include <time.h>
+
+int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
+ void *(*start_routine) (void *), void *arg);
+int pthread_join(pthread_t thread, void **retval);
+
+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");
+}