| 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 : Fri Jan 14 09:13:43 2022 | 
|---|
| 13 | // Update Count     : 73 | 
|---|
| 14 | // | 
|---|
| 15 |  | 
|---|
| 16 | #include <fstream.hfa> | 
|---|
| 17 | #include <thread.hfa> | 
|---|
| 18 | #include <mutex_stmt.hfa> | 
|---|
| 19 |  | 
|---|
| 20 | Duration default_preemption() { return 0; } | 
|---|
| 21 |  | 
|---|
| 22 | // above output used as input to parallel threads | 
|---|
| 23 | thread T2 {}; | 
|---|
| 24 | void main( T2 & ) { | 
|---|
| 25 | int a, b, c, d, e, f, g, h, i; | 
|---|
| 26 | for ( 100 ) {                                                                           // expression protection | 
|---|
| 27 | mutex(sin) sin | a | b | c | d | e | f | g | h | i; | 
|---|
| 28 | } | 
|---|
| 29 | mutex( sin ) {                                                                          // statement protection | 
|---|
| 30 | for ( 100 ) { | 
|---|
| 31 | sin  | a | b | c | d | e | f | g | h | i; | 
|---|
| 32 | } | 
|---|
| 33 | } | 
|---|
| 34 | {                                                                                                       // duplicate protection demonstrating recursive lock | 
|---|
| 35 | ifstream & h1( ifstream & is ) {                                // helper | 
|---|
| 36 | mutex( is ) return is | a | b | c | d;          // unnecessary mutex | 
|---|
| 37 | } | 
|---|
| 38 | ifstream & h2( ifstream & is ) {                                // helper | 
|---|
| 39 | mutex( is ) return is | f | g | h | i;          // unnecessary mutex | 
|---|
| 40 | } | 
|---|
| 41 | mutex( sin ) {                                                                  // unnecessary mutex | 
|---|
| 42 | for ( 5 ) { | 
|---|
| 43 | mutex( sin ) { | 
|---|
| 44 | sin  | a | b | c | d | e | f | g | h | i; | 
|---|
| 45 | sin  | h1 | e | h2;                                     // refactored code | 
|---|
| 46 | } | 
|---|
| 47 | } | 
|---|
| 48 | } | 
|---|
| 49 | } | 
|---|
| 50 | } | 
|---|
| 51 | int main() { | 
|---|
| 52 | processor p; | 
|---|
| 53 | { | 
|---|
| 54 | T2 t[5]; | 
|---|
| 55 | } | 
|---|
| 56 | sout | "done"; | 
|---|
| 57 | } | 
|---|
| 58 |  | 
|---|
| 59 | // Local Variables: // | 
|---|
| 60 | // tab-width: 4 // | 
|---|
| 61 | // compile-command: "cfa io-acquire.cfa" // | 
|---|
| 62 | // End: // | 
|---|