.net - How does System.Threading.Monitor.Enter() work? -
i got question how monitor.enter works. investigated .net framework source code, , shows only:
[system.security.securitycritical] // auto-generated [resourceexposure(resourcescope.none)] [methodimplattribute(methodimploptions.internalcall)] private static extern void reliableenter(object obj, ref bool locktaken);
i guess monitor.enter implementation platform dependent, browsed mono source code , gave :(
yes, critical section assigned each system.object instance may solve, but, don't think actual monitor.lock written this, because creating critical section each system.object cost unlimitedly. (win32 not allow billions of critical section objects in process!)
does know how monitor.enter works? please reply. in advance.
looking @ mono source code, seems create semaphore (using createsemaphore
or similar platform-specific function) when object first locked, , store in object. there appears object pooling going on semaphores , associated monothreadssync structures.
the relevant function static inline gint32 mono_monitor_try_enter_internal (monoobject *obj, guint32 ms, gboolean allow_interruption)
in file mono/metadata/monitor.c
, in case you're interested.
i expect microsoft .net similar.
Comments
Post a Comment