List<ManualResetEvent> doneEventsList = new List<ManualResetEvent>();
productBuilders.ForEach(productBuilder =>
{
doneEventsList.Add(productBuilder.GetDoneEvent());
CustomThreadPool.getSingletonInstance.QueueUserWorkItem(productBuilder.GetAndMapProduct, new Object());
});
WaitHandle.WaitAll(doneEventsList.ToArray());
我對上面的代碼小疑問,不ManualResetEvent的設置爲true
比方說CustomThreadPool
有「Thread
‘類的21個實例列表和’productBuilders
」有3名建設者。在這種情況下,線程獲取計數將從CustomThreadPool獲得'3'。假設如果我沒有在3'GetAndMapProduct
'調用中的任何一個對ManualResetEvent
對象設置'Set()/ true',那麼這3個線程會發生什麼。我的意思是,如果我循環7次以上的代碼,每次獲取3個線程,而不是設置ManualResetEvent
,我不能使用CustomThreadPool類嗎?因爲CustomThreadPool假定所有(7 * 3)線程都忙於工作,它不會有任何免費線程分配?
一個線程池調度程序的工作,甚至是一個自定義線程池調度程序的工作是*不讓*所有線程同時啓動。 – 2013-02-14 14:32:25