main
test-branch
|
Last change
on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago |
|
Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
899 bytes
|
| Line | |
|---|
| 1 | extern void __VERIFIER_error() __attribute__ ((__noreturn__));
|
|---|
| 2 |
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 | #include <pthread.h>
|
|---|
| 5 | #include <string.h>
|
|---|
| 6 |
|
|---|
| 7 | void __VERIFIER_assert(int expression) { if (!expression) { ERROR: __VERIFIER_error();}; return; }
|
|---|
| 8 |
|
|---|
| 9 | const int SIGMA = 16;
|
|---|
| 10 |
|
|---|
| 11 | int *array;
|
|---|
| 12 | int array_index=-1;
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | void *thread(void * arg)
|
|---|
| 16 | {
|
|---|
| 17 | array[array_index] = 1;
|
|---|
| 18 | return 0;
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 |
|
|---|
| 22 | int main()
|
|---|
| 23 | {
|
|---|
| 24 | int tid, sum;
|
|---|
| 25 | pthread_t *t;
|
|---|
| 26 |
|
|---|
| 27 | t = (pthread_t *)malloc(sizeof(pthread_t) * SIGMA);
|
|---|
| 28 | array = (int *)malloc(sizeof(int) * SIGMA);
|
|---|
| 29 |
|
|---|
| 30 | __VERIFIER_assume(t);
|
|---|
| 31 | __VERIFIER_assume(array);
|
|---|
| 32 |
|
|---|
| 33 | for (tid=0; tid<SIGMA; tid++) {
|
|---|
| 34 | array_index++;
|
|---|
| 35 | pthread_create(&t[tid], 0, thread, 0);
|
|---|
| 36 | }
|
|---|
| 37 |
|
|---|
| 38 | for (tid=0; tid<SIGMA; tid++) {
|
|---|
| 39 | pthread_join(t[tid], 0);
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | for (tid=sum=0; tid<SIGMA; tid++) {
|
|---|
| 43 | sum += array[tid];
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | __VERIFIER_assert(sum == SIGMA); // <-- wrong, different threads might use the same array offset when writing
|
|---|
| 47 |
|
|---|
| 48 | return 0;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.