source: CIVL/examples/compare/queue/driver2.cvl@ 08299ed

1.23 2.0 main test-branch
Last change on this file since 08299ed was d186624, checked in by Si Li <sili@…>, 11 years ago

add a general test (driver2.cvl) for concurrent queue

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@2549 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 805 bytes
Line 
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;
11queue_t queue;
12int array[N];
13void thread(int val) {enqueue(&queue, val);dequeue(&queue, &array[val-1]);}
14
15int 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.