1.23
2.0
main
test-branch
| Rev | Line | |
|---|
| [d186624] | 1 | /* General driver to test concurrent queues: Two-Lock queue and
|
|---|
| 2 | * Non-Blocking queue from Michael and Scott
|
|---|
| 3 | */
|
|---|
| 4 |
|
|---|
| 5 | #include <civlc.cvh>
|
|---|
| 6 | #include <stdio.h>
|
|---|
| 7 | #include <assert.h>
|
|---|
| 8 | #include "queue.h"
|
|---|
| 9 |
|
|---|
| 10 | $input int N=3;
|
|---|
| 11 | queue_t queue;
|
|---|
| 12 | int array[N];
|
|---|
| 13 | void thread(int val) {enqueue(&queue, val);dequeue(&queue, &array[val-1]);}
|
|---|
| 14 |
|
|---|
| 15 | int main() { //Test the concurrency
|
|---|
| 16 |
|
|---|
| 17 | initialize(&queue);
|
|---|
| 18 |
|
|---|
| 19 | $parfor(int i: 1 .. N)
|
|---|
| 20 | thread(i);
|
|---|
| 21 |
|
|---|
| 22 | for(int j=0; j < N; j++)
|
|---|
| 23 | printf("array[%d] = %d\t",j, array[j]);
|
|---|
| 24 | printf("\n");
|
|---|
| 25 |
|
|---|
| 26 | assert((array[0]==1&&array[1]==2&&array[2]==3)||(array[0]==1&&array[1]==3&&array[2]==2)||
|
|---|
| 27 | (array[0]==2&&array[1]==3&&array[2]==1)||(array[0]==2&&array[1]==1&&array[2]==3)||
|
|---|
| 28 | (array[0]==3&&array[1]==1&&array[2]==2)||(array[0]==3&&array[1]==2&&array[2]==1));
|
|---|
| 29 |
|
|---|
| 30 | freequeue(queue);
|
|---|
| 31 | }
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.