| 50 | | == Worksharing state == |
| | 50 | == Modeling shared variables == |
| | 51 | |
| | 52 | For each shared variable `v` introduce a second variable `v_state`. The type of `v_state` is obtained from the type of `v` by replacing all primitive types (leaf nodes in the type tree) by `int`. Initially all these ints are -1. |
| | 53 | |
| | 54 | A write to (some part of) the shared variable by thread tid: |
| | 55 | * if the state value is -1, set it to tid, then do the write |
| | 56 | * if the state value is tid, do the write |
| | 57 | * else report a data race. |
| | 58 | |
| | 59 | A read from (some part of) the shared variable by thread tid: |
| | 60 | * if the state value is -1 or tid, do the read |
| | 61 | * else report a data race. |
| | 62 | |
| | 63 | Translating `flush`of (some part of) the shared variable by thread tid: |
| | 64 | * if the state value is -1: no-op |
| | 65 | * if the state value is tid: set it to -1 |
| | 66 | * else: some other thread has some write to the variable which it hasn't flushed. But this thread has not done any writes to that variable (since it last flushed). This is a no-op. |
| | 67 | |
| | 68 | Function |
| | 69 | {{{ |
| | 70 | barrier_and_flush(); |
| | 71 | }}} |
| | 72 | does a barrier on `_barrier` and a flush on all shared variables. |
| | 73 | |
| | 74 | |
| | 75 | == Modeling worksharing state == |
| 101 | | == Translation Strategies == |
| 102 | | |
| 103 | | |
| 104 | | === Translating shared variables === |
| 105 | | |
| 106 | | For each shared variable `v` introduce a second variable `v_state`. The type of `v_state` is obtained from the type of `v` by replacing all primitive types (leaf nodes in the type tree) by `int`. Initially all these ints are -1. |
| 107 | | |
| 108 | | A write to (some part of) the shared variable by thread tid: |
| 109 | | * if the state value is -1, set it to tid, then do the write |
| 110 | | * if the state value is tid, do the write |
| 111 | | * else report a data race. |
| 112 | | |
| 113 | | A read from (some part of) the shared variable by thread tid: |
| 114 | | * if the state value is -1 or tid, do the read |
| 115 | | * else report a data race. |
| 116 | | |
| 117 | | Translating `flush`of (some part of) the shared variable by thread tid: |
| 118 | | * if the state value is -1: no-op |
| 119 | | * if the state value is tid: set it to -1 |
| 120 | | * else: some other thread has some write to the variable which it hasn't flushed. But this thread has not done any writes to that variable (since it last flushed). This is a no-op. |
| 121 | | |
| 122 | | Function |
| 123 | | {{{ |
| 124 | | barrier_and_flush(); |
| 125 | | }}} |
| 126 | | does a barrier on `_barrier` and a flush on all shared variables. |
| | 126 | == Translations of specific directives == |