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. Programming Problem

Programming Problem

Scheduled Pinned Locked Moved C / C++ / MFC
questioncomhelp
3 Posts 2 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.
  • A Offline
    A Offline
    Ahmed Charfeddine
    wrote on last edited by
    #1

    We have a collection of items C(x) A thread A is responsible for performing tasks for those items in a continous and circular way. In coding terms, we would write :

    void doWork() // function executed by thread A
    {
    while(true)
    {
    for each x in C(x)
    perform task(x).
    }
    }

    We have other threads, that write and remove items from C(x) :

    void remove(x);
    void Add(x);

    Now comes the final specification : The function task(x), returns either true or false. If false is returned, then it means, there no need to call task(x) for the same x in the future, unless some thread makes a signal for us that the thread A should be processing all element x. let's call this notification function :

    void NotifyIncludeAllElements();

    What is the best approach here ?

    Push Framework - now released ! http://www.pushframework.com

    _ 1 Reply Last reply
    0
    • A Ahmed Charfeddine

      We have a collection of items C(x) A thread A is responsible for performing tasks for those items in a continous and circular way. In coding terms, we would write :

      void doWork() // function executed by thread A
      {
      while(true)
      {
      for each x in C(x)
      perform task(x).
      }
      }

      We have other threads, that write and remove items from C(x) :

      void remove(x);
      void Add(x);

      Now comes the final specification : The function task(x), returns either true or false. If false is returned, then it means, there no need to call task(x) for the same x in the future, unless some thread makes a signal for us that the thread A should be processing all element x. let's call this notification function :

      void NotifyIncludeAllElements();

      What is the best approach here ?

      Push Framework - now released ! http://www.pushframework.com

      _ Offline
      _ Offline
      _Superman_
      wrote on last edited by
      #2

      x can be a structure variable -

      struct _tagX
      {
      ... Xdata;
      ...
      bool process;
      };

      Now process can be used as a flag to decide if processing is needed.

      «_Superman_»  _I love work. It gives me something to do between weekends.

      _Microsoft MVP (Visual C++)

      Polymorphism in C

      A 1 Reply Last reply
      0
      • _ _Superman_

        x can be a structure variable -

        struct _tagX
        {
        ... Xdata;
        ...
        bool process;
        };

        Now process can be used as a flag to decide if processing is needed.

        «_Superman_»  _I love work. It gives me something to do between weekends.

        _Microsoft MVP (Visual C++)

        Polymorphism in C

        A Offline
        A Offline
        Ahmed Charfeddine
        wrote on last edited by
        #3

        The size of collection C(X) can be so much big, that we might be interested in isolate the elements that are temporarily ignored, in another collection. Further more, if all items are ignored, i am hoping that thread A blocks and not consume CPU for nothing. Finally, the rate of calls to NotifyIncludeAllElements can be so much high, that if we make a shared lock with thread A there, then the performance of processing of A is greatly affected. I tried to think about semaphore, signals, CAS operations, but came up with particular solution, you ca see it in this class I called AbstractDistributor : (Link to CodePlex) http://pushframework.codeplex.com/SourceControl/changeset/view/98598#1909758[^] When I think about the problem I can see many real world scenarios applicable to it. I am wondering if it is already solved in a good way.

        Push Framework - now released ! http://www.pushframework.com

        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