source: tests/concurrency/barrier/generation.cfa @ db19e1d

Last change on this file since db19e1d 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.2 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// generation.cfa -- simple test that validates barriers by printing alphabetical generations
[93b8cf4]8//
9// Author           : Thierry Delisle
10// Created On       : Thu Mar 31 16:43:45 2022
11// Last Modified By :
12// Last Modified On :
13// Update Count     :
14//
15
[31ef267]16// Test validates barrier by having each thread print ABCD...
17// If the barrier is correct it should print all As, all Bs, etc.
[93b8cf4]18
[31ef267]19unsigned NUM_THREADS = 9;
20unsigned NUM_LAPS = 53;
[93b8cf4]21
22#include <concurrency/barrier.hfa>
23#include <fstream.hfa>
24#include <mutex_stmt.hfa>
25#include <thread.hfa>
26
[31ef267]27// The barrier we are testing
[93b8cf4]28barrier bar = { NUM_THREADS };
29
[31ef267]30
[93b8cf4]31thread Tester {};
32void main( Tester & this ) {
[31ef267]33        // Repeat the experiment a few times
[93b8cf4]34        for(NUM_LAPS)
[31ef267]35                // For each letters
[93b8cf4]36                for(c; 'A' ~= 'Z') {
[31ef267]37                        // Yield for chaos
[7bc84b8]38                        yield( prng(this, 10) );
[31ef267]39
40                        // Print the generation, no newline because
[93b8cf4]41                        mutex(sout) sout | c | nonl;
[31ef267]42
43                        // Yield again for more chaos
[7bc84b8]44                        yield( prng(this, 10) );
[31ef267]45
46                        // Block on the barrier
[93b8cf4]47                        block(bar);
48                }
49}
50
51int main() {
52        processor p[4];
53        {
54                Tester testers[NUM_THREADS];
55        }
56        sout | nl;
[d2ad151]57}
Note: See TracBrowser for help on using the repository browser.