Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Implementing of Interruption

Implementing of Interruption

Scheduled Pinned Locked Moved C / C++ / MFC
c++helptutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mohammad torabi
    wrote on last edited by
    #1

    Assume that there are 8 Modules which one of them is Supervisor. They are implemented in C++ classes, so we have 1 Object of Supervisor and more than one Object of other module. The Supervisor assign Tasks to each other module, and whenever they finished their tasks or faced with a problem, they should inform the Supervisor. I think that the best way to implement this behavior is Interruption or something like that. Now, I want to know how to implement it or is there any solution for this problem?

    A S S 3 Replies Last reply
    0
    • M mohammad torabi

      Assume that there are 8 Modules which one of them is Supervisor. They are implemented in C++ classes, so we have 1 Object of Supervisor and more than one Object of other module. The Supervisor assign Tasks to each other module, and whenever they finished their tasks or faced with a problem, they should inform the Supervisor. I think that the best way to implement this behavior is Interruption or something like that. Now, I want to know how to implement it or is there any solution for this problem?

      A Offline
      A Offline
      Albert Holguin
      wrote on last edited by
      #2

      Messaging[^] suits this well and is the native Windows way of handling such tasks... but I'm sure there are many options.

      1 Reply Last reply
      0
      • M mohammad torabi

        Assume that there are 8 Modules which one of them is Supervisor. They are implemented in C++ classes, so we have 1 Object of Supervisor and more than one Object of other module. The Supervisor assign Tasks to each other module, and whenever they finished their tasks or faced with a problem, they should inform the Supervisor. I think that the best way to implement this behavior is Interruption or something like that. Now, I want to know how to implement it or is there any solution for this problem?

        S Offline
        S Offline
        Stefan_Lang
        wrote on last edited by
        #3

        Using interrupts is something you do when your program needs to interact with hardware components that trigger these interrupts. Software can trigger only one type of interrupt, and that is by setting a timer. Your problem is not timed, it is controlled by demand, so setting a timer does not fit that problem. using a timer in this situation is like telling a home owner that instead of reacting to the door bell, he should rather check the door every 5 minutes. I suggest you fire up your preferred search engine and search for the keywords "master slave pattern". This should provide you with lots of interesting links. The master slave pattern is extensively used for organizing the parallelization of complex tasks. Each slave works (potentially) on its own thread, allowing it to work in parallel with its coworkers. That means telling a slave to work requires sending a message to a different thread or process. Since inter-process communication is rather slow, you should prefer the former. In most cases it is not necessary for the slaves to live beyond the scope of their tasks. Therefore, the easiest way is to create a new thread for each slave, whenever you need one. The problem you describe assumes a fixed number of slaves however, implying that these slaves' livetimes are not linked to the tasks they work on. In that case you need a messaging system that allows the supervisor to inform the slaves if and when they are needed, and the slaves to inform the master after they're done. The windows messaging system - as suggested above - should work well for that purpose. The disadvantage of messages is that the master needs to keep track which of his slaves are busy. Also he'll need to queue the tasks if all slaves are busy, until one becomes available. Since you need the ability to queue your tasks anyway, a better solution would be to just push your tasks there, always, and let your slaves pick up work items from there whenever they're idle. That way the master doesn't need to know if or who is available for work. He wouldn't even need to be informed every time a slave is done with his work item; instead, the queue could notify him when it is empty, i. e. the entire workload completed. The only reason not to do that would be if your slaves are specialized to different tasks, but not able to decide for themselves which these are. (e. g. this may happen when the data associated with the tasks come in different formats that the slaves cannot interpret)

        1 Reply Last reply
        0
        • M mohammad torabi

          Assume that there are 8 Modules which one of them is Supervisor. They are implemented in C++ classes, so we have 1 Object of Supervisor and more than one Object of other module. The Supervisor assign Tasks to each other module, and whenever they finished their tasks or faced with a problem, they should inform the Supervisor. I think that the best way to implement this behavior is Interruption or something like that. Now, I want to know how to implement it or is there any solution for this problem?

          S Offline
          S Offline
          Shaheed Legion
          wrote on last edited by
          #4

          Hi, you need too Google the "Observer Pattern" to see a very well explained answer to your question. Hope this helps.

          For awesome websites or just to chat check out my blog for more info. . .

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups