Reputation: 1341
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?:
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; }
Upvotes: 0
Views: 759
Reputation: 84734
The waiting implementation seems fine, just be sure that CloneCustomerPrices is thread safe.
Upvotes: 1
Reputation: 14618
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.
Upvotes: 1