views:

407

answers:

2

Is there a problem with this type of implementation to wait for a batch of threads to complete before moving on, given the following circumstances?:

  • CCR or PFX cannot be used.
  • Customer.Prices collection and newCustomer are NOT being mutated.
  • CloneCustomerPrices performs a deep copy on each of the prices in Customer.Prices collection into a new price Collection.
public List[Customer] ProcessCustomersPrices(List [Customer] Customers)
{
[Code to check Customers and  deep copy Cust data into newCustomers]
List[Thread] ThreadList = new List[Thread]();
foreach(Customer cust in Customers)
{
ThreadList.Add(new Thread(() => CloneCustomerPrices(cust.Prices, newCustomer)));
}

Action runThreadBatch = () =>
      {
           ThreadList.ForEach(t => t.Start());
              ThreadList.All    (t => t.Join([TimeOutNumber]));
      };

runThreadBatch(CopyPriceModelsCallback, null);

[More Processing]
return newCustomers;
}
+1  A: 

Makes sense to me, so long as the threads finish by the timeout. Not sure what newCustomer is (same as cust?). If that's the case I also don't know how to plan to return just one of them.

Adam A
+1  A: 

The waiting implementation seems fine, just be sure that CloneCustomerPrices is thread safe.

Richard Szalay