vendredi 10 mars 2017

Suspending/Resuming an Async Process with std::thread

Let us assume that a following class exists:


class MySession {
 public:
    run(); // can only be invoked once, starts a child _run() process as an async process
    suspend();
    resume();
 private:
    // basic implementation
    run_() {
       while(condition) {
         runMyDefaultOperation();
         // either waits for interval, or if suspended, waits until resume is called 
         waitFor(interval); 
       }
    }
};

This works perfectly fine, but it limits in terms of scalability. This implementation restricts me from suspending in "blocks". To get around this I would need to need to check for a is_suspended state for arbitrarily smaller blocks of code.

Is this design pattern acceptable, or is there another one that I should be utilizing instead for a task such as this?

Aucun commentaire:

Enregistrer un commentaire