| 206 | */ |
| 207 | template<class Tracer> |
| 208 | void |
| 209 | BAB<Tracer>::Worker::run(void) { |
| 210 | /* |
| 211 | * The engine maintains the following invariant: |
| 212 | * - If the current space (cur) is not nullptr, the path always points |
| 213 | * to exactly that space. |
| 214 | * - If the current space (cur) is nullptr, the path always points |
| 215 | * to the next space (if there is any). |
| 216 | * |
| 217 | * This invariant is needed so that no-goods can be extracted properly |
| 218 | * when the engine is stopped or has found a solution. |
| 219 | * |
| 220 | * An additional invariant maintained by the engine is: |
| 221 | * For all nodes stored at a depth less than mark, there |
| 222 | * is no guarantee of betterness. For those above the mark, |
| 223 | * betterness is guaranteed. |
| 224 | * |
| 225 | */ |
| 226 | // Perform initial delay, if not first worker |
| 227 | if (this != engine().worker(0)) |
| 228 | Support::Thread::sleep(Config::initial_delay); |
| 229 | // Okay, we are in business, start working |
| 230 | while (true) { |
| 231 | switch (engine().cmd()) { |
| 232 | case C_WAIT: |
| 233 | // Wait |
| 234 | engine().wait(); |
| 235 | break; |
| 236 | case C_TERMINATE: |
| 237 | // Acknowledge termination request |
| 238 | engine().ack_terminate(); |
| 239 | // Wait until termination can proceed |
| 240 | engine().wait_terminate(); |
| 241 | // Thread will be terminated by returning from run |
| 242 | return; |
| 243 | case C_RESET: |
| 244 | // Acknowledge reset request |
| 245 | engine().ack_reset_start(); |
| 246 | // Wait until reset has been performed |
| 247 | engine().wait_reset(); |
| 248 | // Acknowledge that reset cycle is over |
| 249 | engine().ack_reset_stop(); |
| 250 | break; |
| 251 | case C_WORK: |
| 252 | // Perform exploration work |
| 253 | { |
| 254 | m.acquire(); |
| 255 | if (idle) { |
| 256 | m.release(); |
| 257 | // Try to find new work |
| 258 | find(); |
| 259 | } else if (cur != nullptr) { |
| 260 | start(); |
| 261 | if (stop(engine().opt())) { |
| 262 | // Report stop |
| 263 | m.release(); |
| 264 | engine().stop(); |
| 265 | } else { |
nothing calls this directly
no test coverage detected