1.23
2.0
main
test-branch
|
Last change
on this file since dad2cf06 was 609ffd1, checked in by John Edenhofner <johneden@…>, 12 years ago |
|
Added support for pthread join/exit interaction, new translations, updated documentation and other features
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1080 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
1017 bytes
|
| Rev | Line | |
|---|
| [609ffd1] | 1 | #include <stdlib.h>
|
|---|
| 2 | #include "pthread.cvh"
|
|---|
| 3 | #include <civlc.h>
|
|---|
| 4 | #include <string.h>
|
|---|
| 5 |
|
|---|
| 6 | void __VERIFIER_assert(_Bool expression) {
|
|---|
| 7 | if (!expression) {
|
|---|
| 8 | $assert($false);
|
|---|
| 9 | };
|
|---|
| 10 | return;
|
|---|
| 11 | }
|
|---|
| 12 |
|
|---|
| 13 | char *v;
|
|---|
| 14 |
|
|---|
| 15 | void *thread1(void * arg)
|
|---|
| 16 | {
|
|---|
| 17 | v = (char *)malloc(sizeof(char));
|
|---|
| 18 | return 0;
|
|---|
| 19 | }
|
|---|
| 20 |
|
|---|
| 21 | void *thread2(void *arg)
|
|---|
| 22 | {
|
|---|
| 23 | v[0] = 'X';
|
|---|
| 24 | printf("1");
|
|---|
| 25 | return 0;
|
|---|
| 26 | }
|
|---|
| 27 |
|
|---|
| 28 | void *thread3(void *arg)
|
|---|
| 29 | {
|
|---|
| 30 | v[0] = 'Y';
|
|---|
| 31 | printf("2");
|
|---|
| 32 | return 0;
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 | void *thread0(void *arg)
|
|---|
| 36 | {
|
|---|
| 37 | pthread_t t1, t2, t3, t4, t5;
|
|---|
| 38 |
|
|---|
| 39 | pthread_create(&t1, 0, thread1, 0);
|
|---|
| 40 | pthread_join(t1, 0);
|
|---|
| 41 | pthread_create(&t2, 0, thread2, 0);
|
|---|
| 42 | pthread_create(&t3, 0, thread3, 0);
|
|---|
| 43 | pthread_create(&t4, 0, thread2, 0);
|
|---|
| 44 | pthread_create(&t5, 0, thread2, 0);
|
|---|
| 45 | pthread_join(t2, 0);
|
|---|
| 46 | pthread_join(t3, 0);
|
|---|
| 47 | pthread_join(t4, 0);
|
|---|
| 48 | pthread_join(t5, 0);
|
|---|
| 49 |
|
|---|
| 50 | return 0;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
| 53 | int main(void)
|
|---|
| 54 | {
|
|---|
| 55 | pthread_t t;
|
|---|
| 56 |
|
|---|
| 57 | pthread_create(&t, 0, thread0, 0);
|
|---|
| 58 | pthread_join(t, 0);
|
|---|
| 59 | __VERIFIER_assert(v[0] == 'Y'); // <-- wrong, the only thread that writes 'Y' can be the last to write
|
|---|
| 60 |
|
|---|
| 61 | return 0;
|
|---|
| 62 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.