source: tests/io/io-acquire-no-io.cfa@ f57f6ea0

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

added io-acquire tests with alternative workload to io

  • Property mode set to 100644
File size: 1.8 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
20multiple_acquisition_lock soutLock, sinLock;
21
22long long i;
23void doWork() {
24 for (int j = 0; j < 10000; j++) {
25 i += rand();
26 i -= rand();
27 }
28}
29
30thread T {};
31void main( T & ) {
32 // output from parallel threads should not be scrambled
33
34 for ( 100 ) { // expression protection
35 mutex(soutLock) doWork();
36 }
37 mutex( soutLock ) { // statement protection
38 for ( 100 ) {
39 doWork();
40 }
41 }
42 { // duplicate protection demonstrating recursive lock
43 mutex( soutLock ) { // unnecessary mutex
44 for ( 100 ) {
45 mutex( soutLock ) {
46 doWork();
47 mutex( soutLock ) { doWork(); mutex( soutLock ) doWork(); } // refactored code
48 }
49 }
50 }
51 }
52
53 // above output used as input to parallel threads
54
55 int a, b, c, d, e, f, g, h, i;
56 for ( 100 ) { // expression protection
57 mutex(sinLock) doWork();
58 }
59 mutex( sinLock ) { // statement protection
60 for ( 100 ) {
61 doWork();
62 }
63 }
64 { // duplicate protection demonstrating recursive lock
65 mutex( sinLock ) { // unnecessary mutex
66 for ( 5 ) {
67 mutex( sinLock ) {
68 doWork();
69 mutex( sinLock ) { doWork(); mutex( sinLock ) doWork(); }
70 }
71 }
72 }
73 }
74}
75int main() {
76 processor p;
77 {
78 T t[5];
79 }
80 sout | "done";
81}
82
83// Local Variables: //
84// tab-width: 4 //
85// compile-command: "cfa io-acquire.cfa" //
86// End: //
Note: See TracBrowser for help on using the repository browser.