2020#include < thread>
2121#include < vector>
2222
23- #include < iostream>
24-
2523#include " parallel/HighsCacheAlign.h"
2624#include " parallel/HighsSchedulerConstants.h"
2725#include " parallel/HighsSplitDeque.h"
2826#include " util/HighsInt.h"
2927#include " util/HighsRandom.h"
3028
31-
3229class HighsTaskExecutor {
3330 public:
3431 using cache_aligned = highs::cache_aligned;
@@ -37,11 +34,7 @@ class HighsTaskExecutor {
3734 bool isMain{false };
3835
3936 void dispose ();
40- ~ExecutorHandle () {
41-
42- // TSAN_ANNOTATE_HAPPENS_AFTER(&workerBunk)
43- // dispose();
44- }
37+ ~ExecutorHandle () { dispose (); }
4538 };
4639
4740 private:
@@ -106,16 +99,8 @@ class HighsTaskExecutor {
10699 threadLocalWorkerDeque () = localDeque;
107100
108101 HighsTask* currentTask = ptr->workerBunk ->waitForNewTask (localDeque);
109-
110- // auto ptr = localDeque->getInjectedTask();
111- // TSAN_ANNOTATE_HAPPENS_BEFORE(localDeque->getInjectedTask());
112-
113102 while (currentTask != nullptr ) {
114103 localDeque->runStolenTask (currentTask);
115- // TSAN_ANNOTATE_HAPPENS_BEFORE(currentTask);
116-
117- // TSAN_ANNOTATE_HAPPENS_AFTER(currentTask);
118-
119104
120105 currentTask = ptr->random_steal_loop (localDeque);
121106 if (currentTask != nullptr ) continue ;
@@ -133,35 +118,18 @@ class HighsTaskExecutor {
133118
134119 workerDeques.resize (numThreads);
135120 workerBunk = cache_aligned::make_shared<HighsSplitDeque::WorkerBunk>();
136- #ifdef __has_feature
137- std::cout << " __has_feature is ON" << std::endl;
138- #else
139- std::cout << " __has_feature is OFF" << std::endl;
140- #endif
141- #ifdef TSAN_ENABLED
142- std::cout << " TSAN is ON" << std::endl;
143- #else
144- std::cout << " TSAN is OFF" << std::endl;
145- #endif
146- for (int i = 0 ; i < numThreads; ++i) {
121+ for (int i = 0 ; i < numThreads; ++i)
147122 workerDeques[i] = cache_aligned::make_unique<HighsSplitDeque>(
148123 workerBunk, workerDeques.data (), i, numThreads);
149124
150-
151- // TSAN_ANNOTATE_HAPPENS_AFTER(&workerBunk);
152- }
153-
154125 threadLocalWorkerDeque () = workerDeques[0 ].get ();
155126 workerThreads.reserve (numThreads - 1 );
156127 referenceCount.store (numThreads);
157128
158129 for (int i = 1 , numThreads = static_cast <int >(workerDeques.size ());
159130 i < numThreads; ++i) {
160131 workerThreads.emplace_back (&HighsTaskExecutor::run_worker, i, this );
161- // TSAN_ANNOTATE_HAPPENS_BEFORE(&workerThreads[i]);
162- // std::cout <<"happens before thread " << i << ": " << &workerThreads[i] << std::endl;
163132 }
164-
165133 }
166134
167135 void stopWorkerThreads (bool blocking = false ) {
@@ -172,21 +140,15 @@ std::cout << "TSAN is OFF" << std::endl;
172140 // now inject the null task as termination signal to every worker
173141 for (auto & workerDeque : workerDeques) {
174142 workerDeque->injectTaskAndNotify (nullptr );
175- // TSAN_ANNOTATE_HAPPENS_AFTER(workerDeque->getInjectedTask());
176143 }
177144
178145 // only block if called on main thread, otherwise deadlock may occur
179146 if (blocking && executorHandle.isMain ) {
180147 for (auto & workerThread : workerThreads) {
181- // TSAN_ANNOTATE_HAPPENS_AFTER(&workerThread);
182- // std::cout <<"happens after thread blocking and isMain" << ": " << &workerThread << std::endl;
183148 workerThread.join ();
184- // std::cout <<"happens after join" << std::endl;
185149 }
186150 } else {
187151 for (auto & workerThread : workerThreads) {
188- // TSAN_ANNOTATE_HAPPENS_AFTER(&workerThread);
189- // std::cout <<"happens after thread " << ": " << &workerThread << std::endl;
190152 workerThread.detach ();
191153 }
192154 }
0 commit comments