Queuing Up Threads - Thread Works Until Needing Resource From OtherThread

J

jehugaleahsa

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
 
D

DrewCE

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://msdn2.microsoft.com/en-us/library/system.threading.autoresetevent.aspx

....or ManualResetEvent...
http://msdn2.microsoft.com/en-us/library/system.threading.manualresetevent.aspx

....or WaitHandle.WaitAll and WaitHandle.WaitAny...
http://msdn2.microsoft.com/en-us/library/system.threading.waithandle.aspx

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

-Drew
 
W

William Stacey [C# MVP]

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top