source: tests/concurrency/barrier/last.cfa @ f842032

Last change on this file since f842032 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.9 KB
RevLine 
[a18373a]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// last.cfa -- validates barrier's last hook functionality
[a18373a]8//
9// Author           : Thierry Delisle
10// Created On       : Fri Apr 01 14:24:28 2022
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
16// Test validates barrier correctly blocks threads, and that the last
17// function is called at the appropriate time.
18
19#include <concurrency/barrier.hfa>
20#include <fstream.hfa>
21#include <mutex_stmt.hfa>
22#include <thread.hfa>
23
24const unsigned NUM_LAPS = 223;
25const unsigned NUM_THREADS = 13;
26
27// The barrier we are testing
28barrier bar = { NUM_THREADS };
29
30// The return values of the previous generation.
31volatile unsigned * generation;
32
33// Check that validate is actually getting called as expected;
34volatile unsigned validate_calls = 0;
35
36void validate() {
37        unsigned vc = validate_calls;
38        unsigned expected = generation[0];
39        for(i; 1 ~ NUM_THREADS) {
40                unsigned obtained = generation[i];
41                if( obtained != expected ) {
42                        sout | "Index 0 and" | i | "disagree on current generation:" | expected | "vs" | obtained;
43                }
44        }
45        validate_calls = vc + 1;
46}
47
48thread Tester {
49        unsigned id;
50};
51void main( Tester & this) {
52        park();
53        // Repeat a few times
54        for(l; NUM_LAPS) {
55                // Block
56                block(bar, validate);
57
58                // Update what we thing the generation is
59                generation[this.id]++;
60        }
61}
62
63int main() {
64        // Create the data ans zero it.
65        volatile unsigned gen_data[NUM_THREADS];
66        for(t; NUM_THREADS)
67                gen_data[t] = 0;
68
69        generation = gen_data;
70
71        // Run the experiment
72        processor p[6];
73        {
74                Tester testers[NUM_THREADS];
75                for(i; NUM_THREADS) {
76                        testers[i].id = i;
77                        unpark(testers[i]);
78                }
79        }
80        if(validate_calls != NUM_LAPS) {
81                sout | "Unexpected number of calls to validate: expcted" | NUM_LAPS | ", got" | validate_calls;
82        }
83        sout | "done";
[b2fa3c2]84}
Note: See TracBrowser for help on using the repository browser.