Queuing Up Threads - Thread Works Until Needing Resource From Other Thread

Queuing Up Threads - Thread Works Until Needing Resource From Other Thread

Post by jehugaleah » Sat, 15 Mar 2008 13:15:48


Hello:

At work we have run into an interesting "need". We have a bunch of
customers whose calculations affect one another. Now, to this time, we
have never and we may never have a scenario where two customers affect
one another. So, right now, our system can handle A affecting B.
However, we may someday need to handle A affects B and B affects A. Of
course, neither need to be totally calculated for the other to run.

Ideally, it would be nice to have a list or queue of customers, each
calculating in a different thread. At some deterministic point in a
customer's calculation, we would check to see if they are affected. It
would be nice to tell the thread to simply STOP. We could simply place
the paused thread at the back of the queue. Whenever its turn came
around again, it would be "guarunteed" that it could progress, so we
just unpause it.

In the current system we have to do a long, slow SQL to order
customers. However, this ordering doesn't handle inner-dependencies. I
would like to try to replace the slow SQL with this method, gaining
the benefit of solving the inner-dependency issue at the same time.

The only negative of doing things this way is the memory sitting
around in the inactive, partially completed thread. However, due to
some refactoring, my code only generates a very small memory footprint
until later in the calculation. Also, the number of inner-dependencies
will be small, so that isn't an issue (today).

How can I achieve my goal? Is there a way of doing this without
identifying the affecting customer? I just want to keep it simple by
putting the paused thread after all other threads. if it's not that
simple, let me know.

Thanks,
Travis
 
 
 

Queuing Up Threads - Thread Works Until Needing Resource From Other Thread

Post by DrewC » Sat, 15 Mar 2008 13:35:27

I don't exactly follow what you are trying to do, but there are many ways to
pause a thread until something tells it to start again.

For instance, look up AutoResetEvent...
http://www.yqcomputer.com/

...or ManualResetEvent...
http://www.yqcomputer.com/

...or WaitHandle.WaitAll and WaitHandle.WaitAny...
http://www.yqcomputer.com/

Take a peak at those and see if they are along the lines of what you are
looking for.

-Drew

 
 
 

Queuing Up Threads - Thread Works Until Needing Resource From Other Thread

Post by William St » Sun, 16 Mar 2008 10:48:54

You may also have a look at the CCR library in the ms robotics sdk.