Well, .NET's thread pool is relatively suitable for a smaller task, because each thread is running, in order to exit the thread pool, but
The size of the thread pool is determined (25 in .NET), so if there is too many threads, it will inevitably.
Thread, then wait for the thread in the thread pool to complete.
There is now a thinking, record, ready to practice.
If you have a longer thread, such as a network session, you need to keep it until the client exits, or service
Force to exit, then, first, it is necessary to change the size of the thread pool; second, there is a minimum capacity of a thread pool, which is also a critical.
Value, when the thread greater than this value exits, you can release the thread object, otherwise, only the thread is not used; then, it is thread
Related operations: emptying, new, delete, find.
There is nothing wrong with the size of the thread pool, and my understanding about the critical value is as follows:
1. Create (thread) object takes time;
2, destroy (thread) object takes time;
3, so it can be assumed that the thread pool is an array of objects (in fact, it can be understood according to the buffer), too much no practical work.
Use, but also white waste resources, too small, will create, destroy the object (um, there is a bit like the time slice rotation of the process in the operating system),
Efficiency can not keep up.
Regarding whether the thread is used to use an integer (for the operating efficiency of the machine), the 32-bit machine in .NET
The integer byte is 4 bits, so even if you look for the N-unused thread in the thread pool from the beginning to the order, you only need
N / 32 min (n% 32, 31) jump. As for access, I don't think it is shifted, don't loop, simply put the value of the need to pre-
In the array, 0 = 1, 1 = 2, 2 = 4, 3 = 8, 4 = 16, ..., this efficiency should be higher. How many threads currently can be recorded
Take it, but don't use the basis for creating a new thread (the thread pool has expanded, but the thread less than the threshold has been terminated),
You can record the smallest available thread below the critical value, no remember -1.