1/* 2 * Some or all of this work - Copyright (c) 2006 - 2021, Intel Corp. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without modification, 6 * are permitted provided that the following conditions are met: 7 * 8 * Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * Neither the name of Intel Corporation nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 25 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29/* 30 * Bug 240: 31 * 32 * SUMMARY: No exception when not owner thread runs Release of Global lock 33 * 34 * Note: 35 * 36 * Run this demo by the Threads debug operation 37 * on two threads (use <Threads 2 1 MAIN> command). 38 */ 39 40Mutex(MX00, 0) 41 42Name(i000, 0) // thread 0: succeeded to Acquire Mutex 43Name(i001, 0) // thread 1: after attempt to Release Mutex 44 45Name(cnt0, 0) 46Name(cnt1, 0) 47 48/* 49 * Demo 1: 50 * The expected exception AE_AML_NOT_OWNER doesn't occur when 51 * some thread (thread 1) attempt to Release the Global lock 52 * which is successfully Acquired by another thread (thread 0). 53 * 54 * Thread 0 Acquires the Global lock (\_GL), 55 * then thread 1 attempts to Release that Global lock. 56 * The mentioned exception should arisen there, but in fact - no exception - 57 * the Global lock is successfully Released by another thread (by thread 1). 58 * It is a bug. 59 * 60 * arg0 - Index of current thread 61 */ 62Method(m032, 1) 63{ 64 While (1) { 65 if (LEqual(arg0, 0)) { 66 Store("Thread 0: start of cycle", Debug) 67 if (LNot(cnt0)) { 68 Store(Acquire(\_GL, 0xffff), Local0) 69 if (Local0) { 70 Store("Thread 0: failed to Acquire GL", Debug) 71 err("", zFFF, __LINE__, 0, 0, 0, 0) 72 } else { 73 Store("Thread 0: succeeded to Acquire GL", Debug) 74 Store(1, i000) 75 } 76 } 77 Increment(cnt0) 78 if (LEqual(cnt0, 20)) { 79 break 80 } 81 } elseif (LEqual(arg0, 1)) { 82 Store("Thread 1: start of cycle", Debug) 83 if (i000) { 84 if (LNot(i001)) { 85 Store("Thread 1: before attempt to Release GL", Debug) 86 Release(\_GL) 87 CH04("", 0, 63, 0, __LINE__, 0, 0) // AE_AML_NOT_OWNER 88 Store("Thread 1: after attempt to Release GL", Debug) 89 Store(1, i001) 90 } 91 } 92 Increment(cnt1) 93 if (LEqual(cnt1, 20)) { 94 break 95 } 96 } else { 97 break 98 } 99 Sleep(100) 100 } 101} 102 103/* 104 * Demo 2: 105 * The expected exception AE_AML_NOT_OWNER occurs when some 106 * thread (thread 1) attempt to Release the usual mutex which 107 * is successfully Acquired by another thread (thread 0). 108 * 109 * Identical to m000 but the usual mutex MX00 is substituted instead of Global lock. 110 * 111 * arg0 - Index of current thread 112 */ 113Method(m033, 1) 114{ 115 While (1) { 116 if (LEqual(arg0, 0)) { 117 Store("Thread 0: start of cycle", Debug) 118 if (LNot(cnt0)) { 119 Store(Acquire(MX00, 0xffff), Local0) 120 if (Local0) { 121 Store("Thread 0: failed to Acquire MX00", Debug) 122 err("", zFFF, __LINE__, 0, 0, 0, 0) 123 } else { 124 Store("Thread 0: succeeded to Acquire MX00", Debug) 125 Store(1, i000) 126 } 127 } 128 Increment(cnt0) 129 if (LEqual(cnt0, 20)) { 130 break 131 } 132 } elseif (LEqual(arg0, 1)) { 133 Store("Thread 1: start of cycle", Debug) 134 if (i000) { 135 if (LNot(i001)) { 136 Store("Thread 1: before attempt to Release MX00", Debug) 137 Release(MX00) 138 CH04("", 0, 63, 0, __LINE__, 0, 0) // AE_AML_NOT_OWNER 139 Store("Thread 1: after attempt to Release MX00", Debug) 140 Store(1, i001) 141 } 142 } 143 Increment(cnt1) 144 if (LEqual(cnt1, 20)) { 145 break 146 } 147 } else { 148 break 149 } 150 Sleep(100) 151 } 152} 153