source: tests/io/io-acquire2.cfa @ ec57856

ADTast-experimentalpthread-emulationqualifiedEnum
Last change on this file since ec57856 was e202aa8, checked in by Peter A. Buhr <pabuhr@…>, 2 years ago

add missing file for io-acquire test with no preemption

  • Property mode set to 100644
File size: 2.2 KB
Line 
1//
2// Cforall Version 1.0.0 Copyright (C) 2015 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// io-acquire.cfa --
8//
9// Author           : Peter A. Buhr
10// Created On       : Mon Mar  1 18:40:09 2021
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Mon Jan 10 16:10:20 2022
13// Update Count     : 74
14//
15
16#include <fstream.hfa>
17#include <thread.hfa>
18#include <mutex_stmt.hfa>
19
20Duration default_preemption() { return 0; }
21
22thread T {};
23void main( T & ) {
24        // output from parallel threads should not be scrambled
25
26        for ( 100 ) {                                                                           // expression protection
27                mutex( sout ) sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
28        }
29        mutex( sout ) {                                                                         // statement protection
30                for ( 100 ) {
31                        sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
32                }
33        }
34        {                                                                                                       // duplicate protection demonstrating recursive lock
35                ofstream & h1( ofstream & os ) {                                // helper
36                        mutex( os ) return os | 1 | 2 | 3 | 4;          // unnecessary mutex
37                }
38                ofstream & h2( ofstream & os ) {                                // helper
39                        mutex( os ) return os | 6 | 7 | 8 | 9;          // unnecessary mutex
40                }
41                mutex( sout ) {                                                                 // unnecessary mutex
42                        for ( 100 ) {
43                                mutex( sout ) {
44                                        sout | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9;
45                                        sout | h1 | 5 | h2;                                     // refactored code
46                                }
47                        }
48                }
49        }
50
51        // above output used as input to parallel threads
52
53        int a, b, c, d, e, f, g, h, i;
54        for ( 100 ) {                                                                           // expression protection
55                mutex( sin ) sin | a | b | c | d | e | f | g | h | i;
56        }
57        mutex( sin ) {                                                                          // statement protection
58                for ( 100 ) {
59                        sin  | a | b | c | d | e | f | g | h | i;
60                }
61        }
62        {                                                                                                       // duplicate protection demonstrating recursive lock
63                ifstream & h1( ifstream & is ) {                                // helper
64                        mutex( is ) return is | a | b | c | d;          // unnecessary mutex
65                }
66                ifstream & h2( ifstream & is ) {                                // helper
67                        mutex( is ) return is | f | g | h | i;          // unnecessary mutex
68                }
69                mutex( sin ) {                                                                  // unnecessary mutex
70                        for ( 5 ) {
71                                mutex( sin ) {
72                                        sin  | a | b | c | d | e | f | g | h | i;
73                                        sin  | h1 | e | h2;                                     // refactored code
74                                }
75                        }
76                }
77        }
78}
79int main() {
80        processor p;
81        T t[5];
82}
83
84// Local Variables: //
85// tab-width: 4 //
86// compile-command: "cfa io-acquire2.cfa" //
87// End: //
Note: See TracBrowser for help on using the repository browser.