Implement a more polling-based interface for the tasklets failure mechanism

This commit is contained in:
Lisa Julia Nebel
2024-07-12 15:12:32 +02:00
parent f86623a70c
commit 4d0179cffc
2 changed files with 19 additions and 10 deletions

View File

@@ -199,6 +199,11 @@ public:
}
}
bool failure() const
{
return this->failureFlag_.load(std::memory_order_relaxed);
}
/*!
* \brief Returns the index of the current worker thread.
*
@@ -224,11 +229,6 @@ public:
*/
void dispatch(std::shared_ptr<TaskletInterface> tasklet)
{
if (failureFlag_.load(std::memory_order_relaxed)) {
std::cerr << "Failure flag of the TaskletRunner is set. Not dispatching new tasklets.\n";
exit(EXIT_FAILURE);
}
if (threads_.empty()) {
// run the tasklet immediately in synchronous mode.
while (tasklet->referenceCount() > 0) {
@@ -313,11 +313,6 @@ protected:
void run_()
{
while (true) {
// Check if failure flag is set
if (failureFlag_.load(std::memory_order_relaxed)) {
std::cerr << "Failure flag of the TaskletRunner is set. Exiting thread.\n";
exit(EXIT_FAILURE);
}
// wait until tasklets have been pushed to the queue. first we need to lock
// mutex for access to taskletQueue_

View File

@@ -97,16 +97,30 @@ void execute () {
// Dispatch some successful tasklets
for (int i = 0; i < 5; ++i) {
runner->barrier();
if (runner->failure()) {
exit(EXIT_FAILURE);
}
auto st = std::make_shared<SleepTasklet>(10,i);
runner->dispatch(st);
}
runner->barrier();
if (runner->failure()) {
exit(EXIT_FAILURE);
}
// Dispatch a failing tasklet
auto failingSleepTasklet = std::make_shared<FailingSleepTasklet>(100);
runner->dispatch(failingSleepTasklet);
// Dispatch more successful tasklets
for (int i = 5; i < 10; ++i) {
runner->barrier();
if (runner->failure()) {
exit(EXIT_FAILURE);
}
auto st = std::make_shared<SleepTasklet>(10,i);
runner->dispatch(st);
}