| 1 | // Licensed to the .NET Foundation under one or more agreements. |
| 2 | // The .NET Foundation licenses this file to you under the MIT license. |
| 3 | // See the LICENSE file in the project root for more information. |
| 4 | // --------------------------------------------------------------------------- |
| 5 | // APIThreadStress.h (API thread stresser) |
| 6 | // --------------------------------------------------------------------------- |
| 7 | |
| 8 | // --------------------------------------------------------------------------- |
| 9 | // This class provides a simple base to wrap "thread stress" logic around an API, |
| 10 | // which will (in thread stress mode) cause an API to "fork" onto many threads |
| 11 | // executing the same operation simulatenously. This can help to expose race |
| 12 | // conditions. |
| 13 | // |
| 14 | // Usage: |
| 15 | // |
| 16 | // First, subtype APIThreadStress and override Invoke to implement the operation. |
| 17 | // You will likely need to add data members for the arguments. |
| 18 | // |
| 19 | // Next, inside the API, write code like this: |
| 20 | // |
| 21 | // void MyRoutine(int a1, void *a2) |
| 22 | // { |
| 23 | // class stress : APIThreadStress |
| 24 | // { |
| 25 | // int a1; |
| 26 | // void *a2; |
| 27 | // stress(int a1, void *a2) : a1(a1), a2(a2) |
| 28 | // { DoThreadStress(); } |
| 29 | // void Invoke() { MyRoutine(a1, a2); } |
| 30 | // } ts (a1, a2); |
| 31 | // |
| 32 | // // implementation |
| 33 | // |
| 34 | // // perhaps we have a common sub-point in the routine where we want the threads to |
| 35 | // // queue up and race again |
| 36 | // |
| 37 | // ts.SyncThreadStress(); |
| 38 | // |
| 39 | // // more implementation |
| 40 | // } |
| 41 | // --------------------------------------------------------------------------- |
| 42 | |
| 43 | |
| 44 | #ifndef _APITHREADSTRESS_H_ |
| 45 | #define _APITHREADSTRESS_H_ |
| 46 | |
| 47 | #include "utilcode.h" |
| 48 | |
| 49 | class APIThreadStress |
| 50 | { |
| 51 | public: |
| 52 | BOOL DoThreadStress() { return FALSE; } |
| 53 | static void SyncThreadStress() { } |
| 54 | static void SetThreadStressCount(int count) { } |
| 55 | }; |
| 56 | |
| 57 | #endif // _APITHREADSTRESS_H_ |
| 58 | |