1.23
2.0
main
test-branch
|
Last change
on this file since 764d472 was 16d81051, checked in by John Edenhofner <johneden@…>, 12 years ago |
|
Added more tests to PthreadTests, modified transformer to only add pthread_exit(NULL) to void pointer methods that will be called as a thread. Transforms each main to have a return(0) call at its end so that the thread pool is freed each time (frees upon return)
git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@1236 fb995dde-84ed-4084-dfe6-e5aef3e2452c
|
-
Property mode
set to
100644
|
|
File size:
826 bytes
|
| Rev | Line | |
|---|
| [09bc145] | 1 | #include <stdlib.h>
|
|---|
| 2 | #include <pthread.h>
|
|---|
| 3 | #include <string.h>
|
|---|
| 4 |
|
|---|
| 5 | void __VERIFIER_assert(int expression) { if (!expression) { ERROR: goto ERROR; }; return; }
|
|---|
| 6 |
|
|---|
| 7 | const int SIGMA = 16;
|
|---|
| 8 |
|
|---|
| 9 | int *array;
|
|---|
| [16d81051] | 10 | int array_index = 0;
|
|---|
| [09bc145] | 11 |
|
|---|
| 12 |
|
|---|
| 13 | void *thread(void * arg)
|
|---|
| 14 | {
|
|---|
| 15 | array[array_index] = 1;
|
|---|
| 16 | return 0;
|
|---|
| 17 | }
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | int main()
|
|---|
| 21 | {
|
|---|
| 22 | int tid, sum;
|
|---|
| 23 | pthread_t *t;
|
|---|
| 24 |
|
|---|
| 25 | t = (pthread_t *)malloc(sizeof(pthread_t) * SIGMA);
|
|---|
| 26 | array = (int *)malloc(sizeof(int) * SIGMA);
|
|---|
| 27 |
|
|---|
| [16d81051] | 28 | //__VERIFIER_assume(t);
|
|---|
| 29 | //__VERIFIER_assume(array);
|
|---|
| [09bc145] | 30 |
|
|---|
| 31 | for (tid=0; tid<SIGMA; tid++) {
|
|---|
| 32 | pthread_create(&t[tid], 0, thread, 0);
|
|---|
| 33 | array_index++;
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | for (tid=0; tid<SIGMA; tid++) {
|
|---|
| 37 | pthread_join(t[tid], 0);
|
|---|
| 38 | }
|
|---|
| 39 |
|
|---|
| 40 | for (tid=sum=0; tid<SIGMA; tid++) {
|
|---|
| 41 | sum += array[tid];
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | __VERIFIER_assert(sum == SIGMA); // <-- wrong, different threads might use the same array offset when writing
|
|---|
| 45 |
|
|---|
| 46 | return 0;
|
|---|
| 47 | }
|
|---|
| 48 |
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.