|
2 | 2 | #include "OMC.h" |
3 | 3 | #include <string> |
4 | 4 | #include <iostream> |
5 | | -#include "meta/meta_modelica.h" |
| 5 | +#include <thread> |
| 6 | + |
| 7 | +#define GC_THREADS |
| 8 | +#include "gc.h" |
| 9 | + |
6 | 10 | /* |
7 | 11 | #include <boost/thread.hpp> |
8 | 12 | #include <boost/chrono.hpp> |
9 | 13 | */ |
10 | | -#include <pthread.h> |
11 | | -void runTest(OMCData* omcData, std::string testfolder, std::string omhome) |
| 14 | + |
| 15 | +void runTest(std::string testfolder, std::string omhome) |
12 | 16 | { |
| 17 | + |
| 18 | + GC_stack_base sb; |
| 19 | + GC_get_stack_base(&sb); |
| 20 | + GC_register_my_thread(&sb); |
| 21 | + |
13 | 22 | int status = 0; |
14 | 23 | char *change_dir_results = 0, *mkDirResults = 0, *version = 0, *errorMsg2 = 0, *simulateResult = 0, *clear = 0; |
15 | 24 |
|
| 25 | + OMCData *omcData; |
| 26 | + std::cout << "Initialize OMC, use gcc compiler on folder: " << testfolder << std::endl; |
| 27 | + // if you send in 1 here it will crash on Windows, i need do debug more why this happens |
| 28 | + status = InitOMC(&omcData, "gcc", ""); |
| 29 | + if(status > 0) |
| 30 | + std::cout << "..ok" << std::endl; |
| 31 | + else |
| 32 | + std::cout << "..failed" << std::endl; |
| 33 | + /*----------------------------------------*/ |
| 34 | + |
| 35 | + |
16 | 36 | // create the test folder |
17 | 37 | std::cout << "Create working directory of OMC: " << testfolder << std::endl; |
18 | 38 | std::string mkDir = "mkdir(\"" + testfolder + "\")"; |
@@ -97,39 +117,29 @@ void runTest(OMCData* omcData, std::string testfolder, std::string omhome) |
97 | 117 | std::cout << "..ok " << clear << std::endl; |
98 | 118 | else |
99 | 119 | std::cout << "..failed" << std::endl; |
| 120 | + |
| 121 | + GC_unregister_my_thread(); |
100 | 122 | } |
101 | 123 |
|
| 124 | +#define MAX_THREADS 4 |
| 125 | + |
102 | 126 | int main(int argc, const char* argv[]) |
103 | 127 | { |
104 | | - OMCData *omcData = 0; |
105 | | - int status = 0; |
| 128 | + std::thread threads[MAX_THREADS]; |
| 129 | + int i = 0; |
106 | 130 |
|
107 | 131 | std::cout << "Test OMC C-API dll ..." << std::endl; |
108 | 132 | InitMetaOMC(); |
| 133 | + GC_allow_register_threads(); |
109 | 134 |
|
110 | | - /*----------------------------------------*/ |
111 | | - std::cout << "Initialize OMC, use gcc compiler" << std::endl; |
112 | | - // if you send in 1 here it will crash on Windows, i need do debug more why this happens |
113 | | - status = InitOMC(&omcData, "gcc", ""); |
114 | | - if(status > 0) |
115 | | - std::cout << "..ok" << std::endl; |
116 | | - else |
117 | | - std::cout << "..failed" << std::endl; |
118 | | - /*----------------------------------------*/ |
119 | | - |
120 | | - |
121 | | - std::cout << "starting test 1" << std::endl; |
122 | | - std::string dir = "./tmp1"; |
123 | | - runTest(omcData, dir, ""); |
124 | | - std::cout << "starting test 2" << std::endl; |
125 | | - dir = "./tmp2"; |
126 | | - runTest(omcData, dir, ""); |
127 | | - std::cout << "starting test 3" << std::endl; |
128 | | - dir = "./tmp3"; |
129 | | - runTest(omcData, dir, ""); |
130 | | - |
131 | | - /*------------------------------------------*/ |
| 135 | + for (i = 0; i < MAX_THREADS; i++) |
| 136 | + { |
| 137 | + std::string dir = std::string("./tmp") + std::to_string(i); |
| 138 | + threads[i] = std::thread(runTest, dir, ""); |
| 139 | + } |
132 | 140 |
|
133 | | - FreeOMC(omcData); |
| 141 | + for (i = 0; i < MAX_THREADS; i++) |
| 142 | + if (threads[i].joinable()) |
| 143 | + threads[i].join(); |
134 | 144 | } |
135 | 145 |
|
0 commit comments