source: tests/concurrent/barrier/order.cfa @ 31ef267

ADTast-experimentalenumpthread-emulationqualifiedEnum
Last change on this file since 31ef267 was 31ef267, checked in by Thierry Delisle <tdelisle@…>, 2 years ago

Added comments.

  • Property mode set to 100644
File size: 1.6 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// concurrent/barrier/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 & ) {
36        // Repeat a few times
37        for(l; NUM_LAPS) {
38                // Block and what order we arrived
39                unsigned ret = block(bar);
40
41                // Check what was the last generation of that last thread in this position
42                unsigned g = generation[ret];
43
44                // Is it what we expect?
45                if(g != l) {
46                        // Complain that they are different
47                        sout | "Gen" | l | ": Expeced generation at" | ret | "to be" | l | "was" | g;
48                }
49
50                // Mark the expected next generation
51                generation[ret] = l+1;
52        }
53}
54
55int main() {
56        // Create the data ans zero it.
57        volatile unsigned gen_data[NUM_THREADS];
58        for(t; NUM_THREADS)
59                gen_data[t] = 0;
60
61        generation = gen_data;
62
63        // Run the experiment
64        processor p[4];
65        {
66                Tester testers[NUM_THREADS];
67        }
68        sout | "done";
69}
Note: See TracBrowser for help on using the repository browser.