source: tests/concurrency/barrier/order.cfa @ b5e3a80

Last change on this file since b5e3a80 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
RevLine 
[93b8cf4]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//
[b2fa3c2]7// order.cfa -- validates barriers the return value of
[93b8cf4]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
[31ef267]17// Test validates barrier and block return value by checking
18// that no more than one thread gets the same return value
19
[93b8cf4]20#include <concurrency/barrier.hfa>
21#include <fstream.hfa>
22#include <mutex_stmt.hfa>
23#include <thread.hfa>
24
[31ef267]25const unsigned NUM_LAPS = 173;
26const unsigned NUM_THREADS = 11;
[93b8cf4]27
[31ef267]28// The barrier we are testing
[93b8cf4]29barrier bar = { NUM_THREADS };
[31ef267]30
31// The return values of the previous generation.
32volatile unsigned * generation;
[93b8cf4]33
34thread Tester {};
[5b7fea7]35void main( Tester & this ) {
[31ef267]36        // Repeat a few times
[93b8cf4]37        for(l; NUM_LAPS) {
[5b7fea7]38                // Yield for chaos
[7bc84b8]39                yield( prng(this, 10) );
[5b7fea7]40
[31ef267]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?
[93b8cf4]48                if(g != l) {
[31ef267]49                        // Complain that they are different
[93b8cf4]50                        sout | "Gen" | l | ": Expeced generation at" | ret | "to be" | l | "was" | g;
51                }
[31ef267]52
53                // Mark the expected next generation
54                generation[ret] = l+1;
[93b8cf4]55        }
56}
57
58int main() {
[31ef267]59        // Create the data ans zero it.
60        volatile unsigned gen_data[NUM_THREADS];
[93b8cf4]61        for(t; NUM_THREADS)
62                gen_data[t] = 0;
63
64        generation = gen_data;
65
[31ef267]66        // Run the experiment
[93b8cf4]67        processor p[4];
68        {
69                Tester testers[NUM_THREADS];
70        }
71        sout | "done";
[d2ad151]72}
Note: See TracBrowser for help on using the repository browser.