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:
751 bytes
|
| Line | |
|---|
| 1 | extern void __VERIFIER_error();
|
|---|
| 2 |
|
|---|
| 3 | #include <pthread.h>
|
|---|
| 4 | #include <assert.h>
|
|---|
| 5 |
|
|---|
| 6 | pthread_mutex_t mutex;
|
|---|
| 7 | int data = 0;
|
|---|
| 8 |
|
|---|
| 9 | void *thread1(void *arg)
|
|---|
| 10 | {
|
|---|
| 11 | pthread_mutex_lock(&mutex);
|
|---|
| 12 | data++;
|
|---|
| 13 | pthread_mutex_unlock(&mutex);
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 | void *thread2(void *arg)
|
|---|
| 18 | {
|
|---|
| 19 | pthread_mutex_lock(&mutex);
|
|---|
| 20 | data+=2;
|
|---|
| 21 | pthread_mutex_unlock(&mutex);
|
|---|
| 22 | }
|
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 | void *thread3(void *arg)
|
|---|
| 26 | {
|
|---|
| 27 | pthread_mutex_lock(&mutex);
|
|---|
| 28 | if (data >= 3){
|
|---|
| 29 | ERROR: __VERIFIER_error();
|
|---|
| 30 | ;
|
|---|
| 31 | }
|
|---|
| 32 | pthread_mutex_unlock(&mutex);
|
|---|
| 33 | }
|
|---|
| 34 |
|
|---|
| 35 |
|
|---|
| 36 | int main()
|
|---|
| 37 | {
|
|---|
| 38 | pthread_mutex_init(&mutex, 0);
|
|---|
| 39 |
|
|---|
| 40 | pthread_t t1, t2, t3;
|
|---|
| 41 |
|
|---|
| 42 | pthread_create(&t1, 0, thread1, 0);
|
|---|
| 43 | pthread_create(&t2, 0, thread2, 0);
|
|---|
| 44 | pthread_create(&t3, 0, thread3, 0);
|
|---|
| 45 |
|
|---|
| 46 | pthread_join(t1, 0);
|
|---|
| 47 | pthread_join(t2, 0);
|
|---|
| 48 | pthread_join(t3, 0);
|
|---|
| 49 |
|
|---|
| 50 | return 0;
|
|---|
| 51 | }
|
|---|
| 52 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.