source: tests/io/io-acquire-term-sync.cfa@ a10f6b4

ADT ast-experimental enum forall-pointer-decay pthread-emulation qualifiedEnum
Last change on this file since a10f6b4 was 0ac728b, checked in by caparsons <caparson@…>, 4 years ago

added termination sync io-acquire test

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