MCPcopy Create free account
hub / github.com/Gecode/gecode / run

Method run

gecode/search/par/dfs.hpp:161–299  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159 */
160 template<class Tracer>
161 void
162 DFS<Tracer>::Worker::run(void) {
163 /*
164 * The engine maintains the following invariant:
165 * - If the current space (cur) is not nullptr, the path always points
166 * to exactly that space.
167 * - If the current space (cur) is nullptr, the path always points
168 * to the next space (if there is any).
169 *
170 * This invariant is needed so that no-goods can be extracted properly
171 * when the engine is stopped or has found a solution.
172 *
173 */
174 // Perform initial delay, if not first worker
175 if (this != engine().worker(0))
176 Support::Thread::sleep(Config::initial_delay);
177 // Okay, we are in business, start working
178 while (true) {
179 switch (engine().cmd()) {
180 case C_WAIT:
181 // Wait
182 engine().wait();
183 break;
184 case C_TERMINATE:
185 // Acknowledge termination request
186 engine().ack_terminate();
187 // Wait until termination can proceed
188 engine().wait_terminate();
189 // Thread will be terminated by returning from run
190 return;
191 case C_RESET:
192 // Acknowledge reset request
193 engine().ack_reset_start();
194 // Wait until reset has been performed
195 engine().wait_reset();
196 // Acknowledge that reset cycle is over
197 engine().ack_reset_stop();
198 break;
199 case C_WORK:
200 // Perform exploration work
201 {
202 m.acquire();
203 if (idle) {
204 m.release();
205 // Try to find new work
206 find();
207 } else if (cur != nullptr) {
208 start();
209 if (stop(engine().opt())) {
210 // Report stop
211 m.release();
212 engine().stop();
213 } else {
214 node++;
215 SearchTracer::EdgeInfo ei;
216 if (tracer) {
217 if (path.entries() > 0) {
218 typename Path<Tracer>::Edge& top = path.top();

Callers

nothing calls this directly

Calls 15

stopFunction · 0.85
cmdMethod · 0.80
ack_terminateMethod · 0.80
wait_terminateMethod · 0.80
ack_reset_startMethod · 0.80
wait_resetMethod · 0.80
ack_reset_stopMethod · 0.80
eiMethod · 0.80
idleMethod · 0.80
workerMethod · 0.45
waitMethod · 0.45
acquireMethod · 0.45

Tested by

no test coverage detected