c# - Does ThreadPool.RegisterWaitForSingleObject block the current thread or a thread-pool thread? -
from reading the documentation of threadpool.registerwaitforsingleobject
method, not clear whether:
it blocks current thread while waiting on
eventwaithandle
, commissionswaitortimercallback
on thread pool thread, orit commissions thread pool thread wait on wait handle , on same thread execute
waitortimercallback
once wait handle has been signaled.it blocks current thread , when wait handle signaled, calls
waitortimercallback
on current thread. equivalent functionality ofwaithandle.waitone()
. also, not involve thread pool @ all.
which of 3 do?
it none of above, 2) closest. exact details pretty convoluted, of code buried in clr , has changed across .net versions. can have look-see @ current version in coreclr source, i'll give 10,000 feet view.
key doesn't block, work done dedicated unmanaged thread. called "wait thread" in source code, uses waitformultipleobjects() winapi function wait on registered waits. if there none (left) sleeps. thread woken either queueuserapc() if wait list changes can resume waiting updated list.
once 1 of wait objects signaled, uses threadpool.queueuserworkitem() invoke callback delegate target on threadpool thread. if executeonlyonce
argument true wait handle removed list. , resumes waiting wfmo. thread never ends.
the executeonlyonce
argument important btw, hilarity ensues if pass false , use manualresetevent. thread explosion triggered mre's set() method interesting artifact observe :) can see wait thread in debugger's debug > windows > threads when enable unmanaged debugging. doesn't have interesting name however.
Comments
Post a Comment