I am trying to understand what ThreadPool does, I have this .NET example:
class Program { static void Main() { int c = 2; // Use AutoResetEvent for thread management AutoResetEvent[] arr = new AutoResetEvent[50]; for (int i = 0; i < arr.Length; ++i) { arr[i] = new AutoResetEvent(false); } // Set the number of minimum threads ThreadPool.SetMinThreads(c, 4); // Enqueue 50 work items that run the code in this delegate function for (int i = 0; i < arr.Length; i++) { ThreadPool.QueueUserWorkItem(delegate(object o) { Thread.Sleep(100); arr[(int)o].Set(); // Signals completion }, i); } // Wait for all tasks to complete WaitHandle.WaitAll(arr); } }
Does this accomplish 50 “tasks,” in groups of 2 ( int c), until they end? Or I don’t understand what he is actually doing.
int c
By setting the minimum number of threads, the only thing you ask to do in the .NET environment is to allocate at least 2 threads to the thread pool. You do not ask him to limit himself to only 2.
Thus, there is no guarantee how many threads, in particular, your program will use for this. It depends on your system and many other factors.
, ( , , ), 4 , 3 , 7 , 10 ..
.
?
, :
http://www.albahari.com/threading/
, . , threadpool!:)
MSDN SetMinThreads:
, .
, , 2 . ( , , ), , .
, , , Process Monitor. , , .. , ( ).
: , .NET , . , , , , . , , , .
SetMinThreads() , " ", - .
, , , Thread.Start. , MaxThreads, ( , 250 , , ), . , , , , - , , 5 , , . MaxThreads ; , .
, 50 , 50 ; , 250 , , . 250 , ; , , , "" , , , , reset .
Source: https://habr.com/ru/post/1793728/More articles:Recommendations for using FORMAT_MODULE_PATH - pythonSorl-thumbnail will not delete thumbnails - djangoDjango Using GenericForeignKey to Reference a Model - djangoWhat does the c keyword do in D 2.0? - dReplacing Rails 3 for validation - ruby-on-rails-3smtp server address for testing - smtpBackbone.js does not register Model.hasChanged event - javascriptRails I18n в проверке .rb метод проверки не работает? - rubyInstalling the application gives an "unknown error 18" (Android) - androidinit.d script for SeleniumGrid under CentOS 5.5 - javaAll Articles