source: tests/concurrency/barrier/order.cfa @ 4b75ae9

Last change on this file since 4b75ae9 was b2fa3c2, checked in by Peter A. Buhr <pabuhr@…>, 18 months ago

fix comments referring to concurrency directory

  • Property mode set to 100644
File size: 1.7 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2022 University of Waterloo
3//
4// The contents of this file are covered under the licence agreement in the
5// file "LICENCE" distributed with Cforall.
6//
7// order.cfa -- validates barriers the return value of
8//                                 barrier block
9//
10// Author           : Thierry Delisle
11// Created On       : Fri Apr 01 11:39:09 2022
12// Last Modified By :
13// Last Modified On :
14// Update Count     :
15//
16
17// Test validates barrier and block return value by checking
18// that no more than one thread gets the same return value
19
20#include <concurrency/barrier.hfa>
21#include <fstream.hfa>
22#include <mutex_stmt.hfa>
23#include <thread.hfa>
24
25const unsigned NUM_LAPS = 173;
26const unsigned NUM_THREADS = 11;
27
28// The barrier we are testing
29barrier bar = { NUM_THREADS };
30
31// The return values of the previous generation.
32volatile unsigned * generation;
33
34thread Tester {};
35void main( Tester & this ) {
36        // Repeat a few times
37        for(l; NUM_LAPS) {
38                // Yield for chaos
39                yield( prng(this, 10) );
40
41                // Block and what order we arrived
42                unsigned ret = block(bar);
43
44                // Check what was the last generation of that last thread in this position
45                unsigned g = generation[ret];
46
47                // Is it what we expect?
48                if(g != l) {
49                        // Complain that they are different
50                        sout | "Gen" | l | ": Expeced generation at" | ret | "to be" | l | "was" | g;
51                }
52
53                // Mark the expected next generation
54                generation[ret] = l+1;
55        }
56}
57
58int main() {
59        // Create the data ans zero it.
60        volatile unsigned gen_data[NUM_THREADS];
61        for(t; NUM_THREADS)
62                gen_data[t] = 0;
63
64        generation = gen_data;
65
66        // Run the experiment
67        processor p[4];
68        {
69                Tester testers[NUM_THREADS];
70        }
71        sout | "done";
72}
Note: See TracBrowser for help on using the repository browser.