Example #1
0
        public static bool IsStopped(Thread self)
        {
            RubyThreadInfo.RegisterThread(Thread.CurrentThread);
            RubyThreadStatus status = GetStatus(self);

            return(status == RubyThreadStatus.Sleeping || status == RubyThreadStatus.Completed || status == RubyThreadStatus.Aborted);
        }
Example #2
0
        private static void RaiseAsyncException(Thread thread, Exception exception)
        {
            RubyThreadStatus status = GetStatus(thread);

            // rethrow semantics, preserves the backtrace associated with the exception:
            RubyUtils.RaiseAsyncException(thread, exception);

            if (status == RubyThreadStatus.Sleeping)
            {
                // Thread.Abort can interrupt a thread with ThreadState.WaitSleepJoin. However, Thread.Abort
                // is deferred while the thread is in a catch block. If there is a Kernel.sleep in a catch block,
                // then that sleep will not be interrupted.
                // TODO: We should call Run to nudge the thread if its CurrentException is not-null, and
                // ThreadOps.Stop should have a checkpoint to see whether an async exception needs to be thrown

                // Run(thread);
            }
        }
Example #3
0
        public static MutableString /*!*/ Inspect(RubyContext /*!*/ context, Thread /*!*/ self)
        {
            RubyThreadInfo.RegisterThread(Thread.CurrentThread);

            MutableString result = MutableString.CreateMutable(context.GetIdentifierEncoding());

            result.Append("#<");
            result.Append(context.GetClassDisplayName(self));
            result.Append(':');
            RubyUtils.AppendFormatHexObjectId(result, RubyUtils.GetObjectId(context, self));
            result.Append(' ');

            RubyThreadStatus status = GetStatus(self);

            switch (status)
            {
            case RubyThreadStatus.Unstarted:
                result.Append("unstarted");
                break;

            case RubyThreadStatus.Running:
                result.Append("run");
                break;

            case RubyThreadStatus.Sleeping:
                result.Append("sleep");
                break;

            case RubyThreadStatus.Aborting:
                result.Append("aborting");
                break;

            case RubyThreadStatus.Completed:
            case RubyThreadStatus.Aborted:
                result.Append("dead");
                break;
            }

            result.Append('>');
            return(result);
        }