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