mirror of
https://github.com/OPM/opm-simulators.git
synced 2025-02-25 18:55:30 -06:00
Implement a more polling-based interface for the tasklets failure mechanism
This commit is contained in:
@@ -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_
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user