internal
void
EnsureThreadRequested()
{
int num;
for ( int i = this.numOutstandingThreadRequests; i < ThreadPoolGlobals.processorCount; i = num)
{
num = Interlocked. CompareExchange( ref this.numOutstandingThreadRequests, i + 1, i);
if (num == i)
{
ThreadPool. AdjustThreadsInPool( 1u);
return;
}
}
}
{
int num;
for ( int i = this.numOutstandingThreadRequests; i < ThreadPoolGlobals.processorCount; i = num)
{
num = Interlocked. CompareExchange( ref this.numOutstandingThreadRequests, i + 1, i);
if (num == i)
{
ThreadPool. AdjustThreadsInPool( 1u);
return;
}
}
}
在
ThreadPoolWorkQueue类里的,没用Lock就实现了多线程情况下确保+1操作的一次调用。厉害。