edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C691193 File: Initializers.Generated.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;C691193 (server) 1/5/2009 10:05 AM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Initializers.Generated.cs;critical @@ -5167,11 +5167,11 @@ }); module.DefineLibraryMethod("critical", 0x61, new System.Delegate[] { - new System.Func(IronRuby.Builtins.ThreadOps.Critical), + new System.Func(IronRuby.Builtins.ThreadOps.Critical), }); module.DefineLibraryMethod("critical=", 0x61, new System.Delegate[] { - new System.Func(IronRuby.Builtins.ThreadOps.Critical), + new System.Action(IronRuby.Builtins.ThreadOps.Critical), }); module.DefineLibraryMethod("current", 0x61, new System.Delegate[] { @@ -5199,7 +5199,7 @@ }); module.DefineLibraryMethod("stop", 0x61, new System.Delegate[] { - new System.Action(IronRuby.Builtins.ThreadOps.Stop), + new System.Action(IronRuby.Builtins.ThreadOps.Stop), }); } =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;C691193 File: KernelOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;C691193 (server) 1/5/2009 10:54 AM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/KernelOps.cs;critical @@ -809,7 +809,7 @@ [RubyMethod("sleep", RubyMethodAttributes.PrivateInstance)] [RubyMethod("sleep", RubyMethodAttributes.PublicSingleton)] public static void Sleep(object self) { - ThreadOps.Stop(Thread.CurrentThread); + ThreadOps.DoSleep(); } [RubyMethod("sleep", RubyMethodAttributes.PrivateInstance)] =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ThreadOps.cs;C691193 File: ThreadOps.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ThreadOps.cs;C691193 (server) 1/4/2009 11:36 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Libraries.LCA_RESTRICTED/Builtins/ThreadOps.cs;critical @@ -540,19 +540,22 @@ return value; } - // critical - // critical= - [RubyMethod("critical", RubyMethodAttributes.PublicSingleton)] - public static bool Critical(object self) { + public static bool Critical(RubyContext/*!*/ context, object self) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); - return false; + return context.IsInCriticalRegion; } [RubyMethod("critical=", RubyMethodAttributes.PublicSingleton)] - public static bool Critical(object self, bool value) { + public static void Critical(RubyContext/*!*/ context, object self, bool value) { RubyThreadInfo.RegisterThread(Thread.CurrentThread); - return false; + if (value) { + Monitor.Enter(context.CriticalMonitor); + context.IsInCriticalRegion = true; + } else { + context.IsInCriticalRegion = false; + Monitor.Exit(context.CriticalMonitor); + } } [RubyMethod("current", RubyMethodAttributes.PublicSingleton)] @@ -665,7 +668,14 @@ } [RubyMethod("stop", RubyMethodAttributes.PublicSingleton)] - public static void Stop(object self) { + public static void Stop(RubyContext/*!*/ context, object self) { + if (context.IsInCriticalRegion) { + Critical(context, self, false); + } + DoSleep(); + } + + internal static void DoSleep() { RubyThreadInfo.RegisterThread(Thread.CurrentThread); // TODO: MRI throws an exception if you try to stop the main thread RubyThreadInfo info = RubyThreadInfo.FromThread(Thread.CurrentThread); =================================================================== edit: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs;C691193 File: RubyContext.cs =================================================================== --- $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs;C691193 (server) 1/5/2009 2:02 PM +++ Shelved Change: $/Dev10/feature/vs_langs01/Merlin/Main/Languages/Ruby/Ruby/Runtime/RubyContext.cs;critical @@ -117,6 +117,8 @@ private readonly RubyInputProvider/*!*/ _inputProvider; private readonly Dictionary/*!*/ _globalVariables; private Proc _traceListener; + private readonly object _criticalMonitor = new object(); + private bool _isInCriticalRegion; [ThreadStatic] private bool _traceListenerSuspended; @@ -288,6 +290,15 @@ set { _itemSeparator = value; } } + public object CriticalMonitor { + get { return _criticalMonitor; } + } + + public bool IsInCriticalRegion { + get { return _isInCriticalRegion; } + set { _isInCriticalRegion = value; } + } + public Proc TraceListener { get { return _traceListener; } set { _traceListener = value; } ===================================================================