| 81 | } |
| 82 | |
| 83 | void QWorker::run() { |
| 84 | |
| 85 | while(true) { |
| 86 | access.acquire(); |
| 87 | stopandforget=0; |
| 88 | finished=false; |
| 89 | todo.clear(); |
| 90 | access.release(); |
| 91 | // cout<<"QWorker "<<this<<" : One turn !"<<endl; |
| 92 | QWork cur= wm->getWork(this); |
| 93 | // cout<<"QWorker "<<this<<" got work"<<endl; |
| 94 | if (cur.isStop()) { |
| 95 | return; |
| 96 | } |
| 97 | else if (cur.isWait()) { |
| 98 | // clock_t start = clock(); |
| 99 | // cout<<this<<" WAIT goToWork "<<start<<endl; |
| 100 | goToWork.wait(); |
| 101 | // clock_t stop = clock(); |
| 102 | // cout<<this<<" CONT goToWork "<<stop<<" waited "<<(stop-start)<<endl; |
| 103 | } |
| 104 | else { |
| 105 | access.acquire(); |
| 106 | currentWork = cur; |
| 107 | access.release(); |
| 108 | Strategy ret=solve(); |
| 109 | access.acquire(); |
| 110 | bool forget= (stopandforget == 2); |
| 111 | access.release(); |
| 112 | if (!forget) { |
| 113 | // cout<<"QWorker "<<this<<" returning work..."<<ret.nbTodos()<<" todo in strategy and "<<todo.size()<<" works to do."<<endl; |
| 114 | wm->returnWork(this,ret,todo,cur.root()); |
| 115 | } |
| 116 | else { |
| 117 | // cout<<"QWorker "<<this<<" forgetting work..."<<endl; |
| 118 | |
| 119 | for(list<QWork>::iterator i(todo.begin());i != todo.end();i++) { |
| 120 | (*i).clean(); |
| 121 | } |
| 122 | todo.clear(); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | Strategy QWorker::solve() { |
| 129 | return rsolve(currentWork.getScope(),currentWork.getRemaining()); |