Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b6d80be

Browse files
committed
Remove notifier in executor
1 parent 889e527 commit b6d80be

File tree

1 file changed

+14
-81
lines changed

1 file changed

+14
-81
lines changed

taskflow/core/executor.hpp

Lines changed: 14 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class Executor {
229229
std::atomic<size_t> _num_thieves {0};
230230
std::atomic<bool> _done {0};
231231

232-
Notifier _notifier;
232+
//Notifier _notifier;
233233

234234
std::unique_ptr<ExecutorObserverInterface> _observer;
235235

@@ -261,8 +261,8 @@ class Executor {
261261
// Constructor
262262
inline Executor::Executor(unsigned N) :
263263
_workers {N},
264-
_waiters {N},
265-
_notifier {_waiters} {
264+
_waiters {N} {
265+
//_notifier {_waiters} {
266266
_spawn(N);
267267
}
268268

@@ -274,7 +274,7 @@ inline Executor::~Executor() {
274274

275275
// shut down the scheduler
276276
_done = true;
277-
_notifier.notify(true);
277+
//_notifier.notify(true);
278278

279279
for(auto& t : _threads){
280280
t.join();
@@ -354,6 +354,7 @@ inline unsigned Executor::_find_victim(unsigned thief) {
354354
return _workers.size();
355355
}
356356

357+
357358
// Function: _explore_task
358359
inline void Executor::_explore_task(unsigned thief, std::optional<Node*>& t) {
359360

@@ -363,59 +364,32 @@ inline void Executor::_explore_task(unsigned thief, std::optional<Node*>& t) {
363364
const unsigned l = 0;
364365
const unsigned r = _workers.size() - 1;
365366

366-
const size_t F = (_workers.size() + 1) << 1;
367-
const size_t Y = 100;
368-
369-
size_t f = 0;
370-
size_t y = 0;
371-
372367
// explore
373368
while(!_done) {
374369

370+
std::this_thread::yield();
371+
375372
unsigned vtm = std::uniform_int_distribution<unsigned>{l, r}(
376373
_workers[thief].rdgen
377374
);
378375

379376
t = (vtm == thief) ? _queue.steal() : _workers[vtm].queue.steal();
380377

381378
if(t) {
382-
break;
383-
}
384-
385-
if(f++ > F) {
386-
if(std::this_thread::yield(); y++ > Y) {
387-
break;
388-
}
389-
}
390-
391-
/*if(auto vtm = _find_victim(thief); vtm != _workers.size()) {
392-
t = (vtm == thief) ? _queue.steal() : _workers[vtm].queue.steal();
393-
// successful thief
394-
if(t) {
395-
break;
396-
}
379+
return ;
397380
}
398-
else {
399-
if(f++ > F) {
400-
if(std::this_thread::yield(); y++ > Y) {
401-
break;
402-
}
403-
}
404-
}*/
405381
}
406382

407383
}
408384

385+
409386
// Procedure: _exploit_task
410387
inline void Executor::_exploit_task(unsigned i, std::optional<Node*>& t) {
411388

412389
assert(!_workers[i].cache);
413390

414391
if(t) {
415392
auto& worker = _workers[i];
416-
if(_num_actives.fetch_add(1) == 0 && _num_thieves == 0) {
417-
_notifier.notify(false);
418-
}
419393
do {
420394
_invoke(i, *t);
421395

@@ -428,64 +402,23 @@ inline void Executor::_exploit_task(unsigned i, std::optional<Node*>& t) {
428402
}
429403

430404
} while(t);
431-
432-
--_num_actives;
433405
}
434406
}
435407

408+
436409
// Function: _wait_for_task
437410
inline bool Executor::_wait_for_task(unsigned me, std::optional<Node*>& t) {
438411

439-
wait_for_task:
440-
441412
assert(!t);
442413

443-
++_num_thieves;
444-
445-
explore_task:
446-
447414
if(_explore_task(me, t); t) {
448-
if(auto N = _num_thieves.fetch_sub(1); N == 1) {
449-
_notifier.notify(false);
450-
}
451415
return true;
452416
}
453-
454-
_notifier.prepare_wait(&_waiters[me]);
455-
456-
//if(auto vtm = _find_victim(me); vtm != _workers.size()) {
457-
if(!_queue.empty()) {
458-
459-
_notifier.cancel_wait(&_waiters[me]);
460-
//t = (vtm == me) ? _queue.steal() : _workers[vtm].queue.steal();
461-
462-
if(t = _queue.steal(); t) {
463-
if(auto N = _num_thieves.fetch_sub(1); N == 1) {
464-
_notifier.notify(false);
465-
}
466-
return true;
467-
}
468-
else {
469-
goto explore_task;
470-
}
471-
}
472-
473-
if(_done) {
474-
_notifier.cancel_wait(&_waiters[me]);
475-
_notifier.notify(true);
476-
--_num_thieves;
417+
else {
477418
return false;
478419
}
479420

480-
if(_num_thieves.fetch_sub(1) == 1 && _num_actives) {
481-
_notifier.cancel_wait(&_waiters[me]);
482-
goto wait_for_task;
483-
}
484-
485-
// Now I really need to relinguish my self to others
486-
_notifier.commit_wait(&_waiters[me]);
487-
488-
return true;
421+
assert(false);
489422
}
490423

491424
// Function: make_observer
@@ -563,7 +496,7 @@ inline void Executor::_schedule(Node* node, bool bypass) {
563496
_queue.push(node);
564497
}
565498

566-
_notifier.notify(false);
499+
//_notifier.notify(false);
567500
}
568501

569502
// Procedure: _schedule
@@ -603,7 +536,7 @@ inline void Executor::_schedule(PassiveVector<Node*>& nodes) {
603536
}
604537
}
605538

606-
_notifier.notify(false);
539+
//_notifier.notify(false);
607540
}
608541

609542
// Procedure: _init_module_node

0 commit comments

Comments
 (0)