Package org.jruby
Class RubyThread
java.lang.Object
org.jruby.RubyBasicObject
org.jruby.RubyObject
org.jruby.RubyThread
- All Implemented Interfaces:
Serializable,Cloneable,Comparable<IRubyObject>,InstanceVariables,InternalVariables,IRubyObject,ExecutionContext,CoreObjectType
Implementation of Ruby's
Thread class. Each Ruby thread is
mapped to an underlying Java Virtual Machine thread.
Thread encapsulates the behavior of a thread of execution, including the main
thread of the Ruby script. In the descriptions that follow, the parameter
aSymbol refers to a symbol, which is either a quoted string or a
Symbol (such as :name).
Note: For CVS history, see ThreadClass.java.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceDeprecated.static classstatic interfacestatic final classprivate static classA Task for sleeping.static enumThread statusesstatic interfacestatic interfaceNested classes/interfaces inherited from class org.jruby.RubyObject
RubyObject.DataNested classes/interfaces inherited from class org.jruby.RubyBasicObject
RubyBasicObject.Finalizer -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhether this thread should try to abort the program on exceptionprivate final booleanWhether this is an "adopted" thread not created by Ruby codeprivate BlockingIO.Conditionprivate WeakReference<ThreadContext>Weak reference to the ThreadContext for this thread.private final Map<Object,IRubyObject> Context-local variables, internal-ish thread localsprivate RubyThread.BlockingTaskDeprecated.private Selectorprivate booleanWhether or not this thread has been disposed ofprivate IRubyObjectPer-thread "current exception"private ThrowableThe exception currently being raised out of the thread.private RubyThreadprivate Map<IRubyObject,IRubyObject> Fiber-local variablesprivate Stringprivate IRubyObjectThe final value resulting from the thread's executionprivate static final RubyHash.VisitorWithStateThe list of locks this thread currently holds, so they can be released on exitprivate static final AtomicIntegerFieldUpdater<RubyThread>private static final intprivate static final intprivate static final intprivate static final intprivate intInterrupt flagsprivate intInterrupt mask to use for disabling certain typesStack of interrupt masks active for this threadprivate intprivate static final Loggerprivate static final Stringprivate static final RubyHash[]private static final intprivate final Queue<IRubyObject>Mail slot for cross-thread eventsprivate booleanShort circuit to avoid-re-scanning for interruptsprivate static final intprivate booleanWhether this thread should report_on_exception when this thread GCs, when it terminates, or neverstatic final intstatic final intprivate static final Stringprivate final RubyThread.SleepTask2Thread-local tuple used for sleeping (semaphore, millis, nanos)private RubyThread.StatusCurrent status in an atomic referenceprivate static final AtomicReferenceFieldUpdater<RubyThread,RubyThread.Status> private RubyThreadGroupThe ThreadGroup to which this thread belongsprivate ThreadLikeThe thread-like think that is actually executingprivate Map<IRubyObject,IRubyObject> Normal thread-local variables (local to parent thread if in a fiber)private static final intprivate static final intprivate ObjectArgument to pass to the unblockerprivate RubyThread.UnblockerA function to use to unblock this thread, if possibleprivate static final com.headius.backport9.stack.StackWalkerFields inherited from class org.jruby.RubyObject
IVAR_INSPECTING_OBJECT_ALLOCATOR, OBJECT_ALLOCATOR, REIFYING_OBJECT_ALLOCATORFields inherited from class org.jruby.RubyBasicObject
ALL_F, BASICOBJECT_ALLOCATOR, COMPARE_BY_IDENTITY_F, ERR_INSECURE_SET_INST_VAR, FALSE_F, FL_USHIFT, flags, FROZEN_F, IS_OVERLAID_F, metaClass, NEVER, NIL_F, REFINED_MODULE_F, STAMP_OFFSET, TAINTED_F, UNDEF, UNTRUST_F, USER0_F, USER1_F, USER2_F, USER3_F, USER4_F, USER5_F, USER6_F, USER7_F, USER8_F, USER9_F, USERA_F, VAR_TABLE_OFFSET, varTable, varTableStamp -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedRubyThread(Ruby runtime, RubyClass type, boolean adopted) RubyThread(Ruby runtime, RubyClass klass, Runnable runnable) -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.abort_on_exception(ThreadContext context) static RubyBooleanabort_on_exception(ThreadContext context, IRubyObject recv) Returns the status of the global ``abort on exception'' condition.static IRubyObjectabort_on_exception_set(ThreadContext context, IRubyObject recv, IRubyObject value) static IRubyObjectabort_on_exception_set_x(IRubyObject recv, IRubyObject value) Deprecated.static RubyBooleanDeprecated.private booleanabortOnException(Ruby runtime) add_trace_func(ThreadContext context, IRubyObject trace_func, Block block) static IRubyObjectadd_trace_func(ThreadContext context, IRubyObject recv, IRubyObject trace_func, Block block) private voidaddToCorrectThreadGroup(ThreadContext context) static RubyThreadadopt(Ruby runtime, ThreadService service, Thread thread) static RubyThreadadopt(IRubyObject recv, Thread t) private static RubyThreadadoptThread(Ruby runtime, ThreadService service, RubyClass recv, Thread thread) voidalive_p()private booleanbacktrace(ThreadContext context) backtrace(ThreadContext context, IRubyObject level) backtrace(ThreadContext context, IRubyObject[] args) Deprecated.backtrace(ThreadContext context, IRubyObject level, IRubyObject length) backtrace_locations(ThreadContext context) backtrace_locations(ThreadContext context, IRubyObject level) backtrace_locations(ThreadContext context, IRubyObject[] args) Deprecated.backtrace_locations(ThreadContext context, IRubyObject level, IRubyObject length) backtrace20(ThreadContext context, IRubyObject[] args) Deprecated.private IRubyObjectbacktraceInternal(ThreadContext callerContext, IRubyObject level, IRubyObject length) private IRubyObjectbacktraceLocationsInternal(ThreadContext callerContext, IRubyObject level, IRubyObject length) voidbeDead()voidDeprecated.voidbeforeBlockingCall(ThreadContext context) voidPerform pre-execution tasks once the native thread is running, but we have not yet called the Ruby code for the thread.voidblockingThreadPoll(ThreadContext context) private static intcheckInterruptMask(ThreadContext context, IRubyObject sym) voidcheckMail(ThreadContext context) Deprecated.voidcleanTerminate(IRubyObject result) voidprivate static voidcopyInterrupts(ThreadContext context, Vector<RubyHash> sourceStack, Vector<RubyHash> targetStack) static RubyClasscreateThreadClass(Ruby runtime) static RubyThreadcurrent(IRubyObject recv) voidUsed for finalizers that need to kill a Ruby thread.voiddispose()Dispose of the current thread by tidying up connections to other stuffvoidbooleanThis override does not do a "checked" dispatch.voidexceptionRaised(Throwable throwable) For handling all exceptions bubbling out of threadsvoidexceptionRaised(RaiseException exception) static IRubyObjectexclusive(ThreadContext context, IRubyObject recv, Block block) Deprecated.voidDeprecated.private voidexecuteInterrupts(ThreadContext context, boolean blockingTiming) <Data> intexecuteReadWrite(ThreadContext context, Data data, byte[] bytes, int start, int length, RubyThread.ReadWrite<Data> task) Execute an interruptible read or write operation with the given byte range and data object.<Data,Return>
ReturnexecuteTask(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task) private <Data,Return>
ReturnexecuteTask(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task, boolean blocking) <Data,Return>
ReturnexecuteTask(ThreadContext context, Data data, RubyThread.Task<Data, Return> task) <Data,Return>
ReturnexecuteTaskBlocking(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task) <Data,Return>
ReturnexecuteTaskBlocking(ThreadContext context, Data data, RubyThread.Task<Data, Return> task) static IRubyObjectexit(IRubyObject receiver, Block block) voidfetch(ThreadContext context, IRubyObject key, Block block) fetch(ThreadContext context, IRubyObject key, IRubyObject _default, Block block) private IRubyObjectgenericKill(Ruby runtime, RubyThread currentThread) private IRubyObjectgenericRaise(ThreadContext context, RubyThread currentThread, IRubyObject... args) final Map<Object,IRubyObject> private Map<IRubyObject,IRubyObject> private intprivate static MutexgetMutexForThreadExclusive(ThreadContext context, RubyClass recv) getName()private RubyThread.Statusprivate RubySymbolgetSymbolKey(IRubyObject originalKey) private Map<IRubyObject,IRubyObject> private Map<IRubyObject,IRubyObject> group()static IRubyObjecthandle_interrupt(ThreadContext context, IRubyObject self, IRubyObject _mask, Block block) private IRubyObjecthandleInterrupt(ThreadContext context, RubyHash mask, BiFunction<ThreadContext, IRubyObject, IRubyObject> block) private <StateType>
IRubyObjecthandleInterrupt(ThreadContext context, RubyHash mask, StateType state, BiFunction<ThreadContext, StateType, IRubyObject> block) inthashCode()This override does not do "checked" dispatch since Object usually has #hash defined.private Stringprivate static longincAndGetThreadCount(Ruby runtime) initialize(ThreadContext context, IRubyObject[] args, Block block) private static voidinitThreadName(Ruby runtime, Thread thread, String file, int line) inspect()rb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj.inspect(ThreadContext context) voidinternalRaise(IRubyObject[] args) Deprecated.voidbooleanbooleanbooleanisAlive()private booleanbooleanstatic intjavaPriorityToRubyPriority(int javaPriority) join(IRubyObject[] args) Deprecated.join(ThreadContext context, IRubyObject[] args) key_p(IRubyObject key) Deprecated.key_p(ThreadContext context, IRubyObject key) keys()kill()static IRubyObjectkill(IRubyObject receiver, IRubyObject rubyThread, Block block) static RubyArraylist(IRubyObject recv) voidAcquire the given lock, holding a reference to it for cleanup on thread termination.voidlockInterruptibly(Lock lock) Acquire the given lock interruptibly, holding a reference to it for cleanup on thread termination.static RubyThreadmain(IRubyObject recv) static RubyThreadmainThread(IRubyObject receiver) private RubyThread.Statusstatic IRubyObjectnewInstance(IRubyObject recv, IRubyObject[] args, Block block) Thread.newprivate static booleanop_aref(IRubyObject key) Deprecated.op_aref(ThreadContext context, IRubyObject key) op_aset(IRubyObject key, IRubyObject value) static IRubyObjectpass(IRubyObject recv) Deprecated.static IRubyObjectpass(ThreadContext context, IRubyObject recv) pending_interrupt_p(ThreadContext context, IRubyObject[] args) static IRubyObjectpending_interrupt_p(ThreadContext context, IRubyObject self, IRubyObject[] args) private booleanprivate intpendingInterruptCheckMask(ThreadContext context, IRubyObject err) private voidprivate IRubyObjectpendingInterruptDeque(ThreadContext context, int timing) private voidprivate booleanvoidvoidpollThreadEvents(ThreadContext context) voidpollThreadEvents(ThreadContext context, boolean blocking) Poll for thread events (raise, kill), propagating only events that are unmasked (seehandle_interrupt(ThreadContext, IRubyObject, IRubyObject, Block)or intended to fire before blocking operations if blocking = true.private voidpostponedJobFlush(ThreadContext context) private IRubyObjectprepareRaiseException(ThreadContext context, IRubyObject[] args, Block block) protected voidpriority()priority_set(IRubyObject priority) final IRubyObjectraise(IRubyObject exception) Simplified utility method for just raising an existing exception in this thread.raise(IRubyObject[] args, Block block) Deprecated.final IRubyObjectraise(IRubyObject exception, RubyString message) Simplified utility method for just raising an existing exception in this thread.raise(ThreadContext context, IRubyObject[] args, Block block) voidreceiveMail(ThreadService.Event event) Deprecated.report_on_exception(ThreadContext context) static IRubyObjectreport_on_exception(ThreadContext context, IRubyObject self) report_on_exception_set(ThreadContext context, IRubyObject state) static IRubyObjectreport_on_exception_set(ThreadContext context, IRubyObject self, IRubyObject state) static intrubyPriorityToJavaPriority(int rubyPriority) run()booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.booleanPerform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.booleanDeprecated.set_trace_func(ThreadContext context, IRubyObject trace_func, Block block) voidsetAbortOnException(boolean abortOnException) voidsetContext(ThreadContext context) setErrorInfo(IRubyObject errorInfo) voidsetFiberCurrentThread(RubyThread fiberCurrentThread) voidSet the pending interrupt flag.setName(IRubyObject name) voidsetReportOnException(boolean reportOnException) (package private) voidsetThreadGroup(RubyThreadGroup rubyThreadGroup) booleansleep(long millis) Sleep the current thread for millis, waking up on any thread interrupts.voidRelease lock and sleep.voidRelease lock and sleep for the specified number of milliseconds.static RubyThreadstart(IRubyObject recv, IRubyObject[] args, Block block) Basically the same as Thread.new .static RubyThreadstart19(IRubyObject recv, IRubyObject[] args, Block block) Deprecated.private static RubyThreadstartThread(IRubyObject recv, IRubyObject[] args, boolean callInit, Block block) private ThreadstartThread(ThreadContext context, Runnable runnable) protected static RubyThreadstartWaiterThread(Ruby runtime, long pid, Block block) status()status(ThreadContext context) static IRubyObjectstop(ThreadContext context, IRubyObject receiver) stop_p()thread_variable_get(ThreadContext context, IRubyObject key) thread_variable_p(ThreadContext context, IRubyObject key) thread_variable_set(ThreadContext context, IRubyObject key, IRubyObject value) thread_variables(ThreadContext context) private static voidprivate voidtoKill()toString()The default toString method is just a wrapper that calls the Ruby "to_s" method.booleanTry to acquire the given lock, adding it to a list of held locks for cleanup on thread termination if it is acquired.static <StateType>
IRubyObjectuninterruptible(ThreadContext context, StateType state, BiFunction<ThreadContext, StateType, IRubyObject> f) Run the providedBiFunctionwithout allowing for any cross-thread interrupts (equivalent to callinghandle_interrupt(ThreadContext, IRubyObject, IRubyObject, Block)with Object => :never.voidRelease the given lock and remove it from the list of locks to be released on thread termination.voidRelease all locks held.value()Deprecated.value(ThreadContext context) booleanwait_timeout(IRubyObject o, Double timeout) booleanwaitForIO(ThreadContext context, RubyIO io, int ops) wakeup()Methods inherited from class org.jruby.RubyObject
attachToObjectSpace, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, callInit, convertToType, createObjectClass, dig, dig1, dig2, eqlInternal, equalInternal, getNativeClassIndex, inspect, op_eqq, puts, specificEval, toRubyStringMethods inherited from class org.jruby.RubyBasicObject
addFinalizer, anyToString, asJavaString, asString, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callMethod, callSuper, checkArrayType, checkCallMethod, checkCallMethod, checkFrozen, checkStringType, checkStringType19, compareTo, convertToArray, convertToFloat, convertToHash, convertToInteger, convertToInteger, convertToInteger, convertToString, copyInstanceVariablesInto, copySpecialInstanceVariables, createBasicObjectClass, dataGetStruct, dataGetStructChecked, dataWrapStruct, decode, defaultToJava, display, dup, ensureInstanceVariablesSettable, eql, eql_p, equal_p, equal_p19, evalUnder, extend, fastGetInstanceVariable, fastGetInternalVariable, fastHasInstanceVariable, fastHasInternalVariable, fastSetInstanceVariable, fastSetInternalVariable, freeze, frozen_p, getFFIHandle, getFlag, getInstanceEvalClass, getInstanceVariable, getInstanceVariableList, getInstanceVariableNameList, getInstanceVariables, getInternalVariable, getInternalVariables, getJavaClass, getMetaClass, getMetaClass, getNativeHandle, getNativeTypeIndex, getObjectId, getRuntime, getSingletonClass, getSingletonClassClone, getSingletonClassCloneAndAttach, getType, getVariable, getVariableCount, getVariableList, getVariableNameList, hash, hashyInspect, hasInstanceVariable, hasInstanceVariables, hasInternalVariable, hasVariables, id, infectBy, infectBy, infectBy, initialize, initialize_copy, initialize19, inspectHashCode, instance_eval, instance_eval, instance_eval, instance_eval, instance_eval19, instance_eval19, instance_eval19, instance_eval19, instance_exec, instance_exec19, instance_of_p, instance_variable_defined_p, instance_variable_get, instance_variable_set, instance_variables, instance_variables19, isBuiltin, isClass, isFalse, isFrozen, isImmediate, isModule, isNil, isSpecialConst, isSpecialObject, isTaint, isTrue, isUntrusted, kind_of_p, makeMetaClass, method, method_missing, method_missing19, method19, methods, methods, methods19, methodsImpl, nil_p, nonFixnumHashCode, OBJ_INIT_COPY, objInitCopy, op_cmp, op_equal, op_equal_19, op_match, op_match19, op_not, op_not_equal, op_not_match, private_methods, private_methods19, protected_methods, protected_methods19, public_methods, public_methods19, rbClone, rbClone, rbInspect, recacheBuiltinMethods, remove_instance_variable, removeFinalizers, removeInstanceVariable, removeInternalVariable, respond_to_p, respond_to_p, respond_to_p, respond_to_p19, respond_to_p19, respondsTo, respondsToMissing, respondsToMissing, send, send, send, send, send, send19, send19, send19, send19, setFFIHandle, setFlag, setFrozen, setInstanceVariable, setInternalVariable, setMetaClass, setNativeHandle, setTaint, setUntrusted, setVariable, singleton_method, singleton_method_added, singleton_method_added19, singleton_method_removed, singleton_method_removed19, singleton_method_undefined, singleton_method_undefined19, singleton_methods, specificEval, specificEval, specificEval, specificEval, syncVariables, syncVariables, taint, taint, tainted, tainted_p, testFrozen, testFrozen, to_a, to_a, to_s, toJava, trust, type, type_deprecated, untaint, untrust, untrusted_p, validateInstanceVariable, validateInstanceVariable, validateInstanceVariable, variableTableContains, variableTableFastContains, variableTableFastFetch, variableTableFastStore, variableTableFetch, variableTableRemove, variableTableStore, variableTableSync, yieldUnder, yieldUnder
-
Field Details
-
LOG
-
WALKER
private static final com.headius.backport9.stack.StackWalker WALKER -
threadImpl
The thread-like think that is actually executing -
fiberLocalVariables
Fiber-local variables -
threadLocalVariables
Normal thread-local variables (local to parent thread if in a fiber) -
contextVariables
Context-local variables, internal-ish thread locals -
abortOnException
private volatile boolean abortOnExceptionWhether this thread should try to abort the program on exception -
reportOnException
private volatile boolean reportOnExceptionWhether this thread should report_on_exception when this thread GCs, when it terminates, or never -
finalResult
The final value resulting from the thread's execution -
file
-
line
private int line -
exitingException
The exception currently being raised out of the thread. We reference it here to continue propagating it while handling thread shutdown logic and abort_on_exception. -
threadGroup
The ThreadGroup to which this thread belongs -
errorInfo
Per-thread "current exception" -
contextRef
Weak reference to the ThreadContext for this thread. -
interruptMaskStack
Stack of interrupt masks active for this thread -
sleepTask
Thread-local tuple used for sleeping (semaphore, millis, nanos) -
adopted
private final boolean adoptedWhether this is an "adopted" thread not created by Ruby code -
RUBY_MIN_THREAD_PRIORITY
public static final int RUBY_MIN_THREAD_PRIORITY- See Also:
-
RUBY_MAX_THREAD_PRIORITY
public static final int RUBY_MAX_THREAD_PRIORITY- See Also:
-
status
Current status in an atomic reference -
STATUS
-
pendingInterruptQueue
Mail slot for cross-thread events -
unblockFunc
A function to use to unblock this thread, if possible -
unblockArg
Argument to pass to the unblocker -
heldLocks
The list of locks this thread currently holds, so they can be released on exit -
disposed
private volatile boolean disposedWhether or not this thread has been disposed of -
interruptFlag
private volatile int interruptFlagInterrupt flags -
interruptMask
private volatile int interruptMaskInterrupt mask to use for disabling certain types -
pendingInterruptQueueChecked
private volatile boolean pendingInterruptQueueCheckedShort circuit to avoid-re-scanning for interrupts -
currentSelector
-
fiberCurrentThread
-
INTERRUPT_FLAG_UPDATER
-
TIMER_INTERRUPT_MASK
private static final int TIMER_INTERRUPT_MASK- See Also:
-
PENDING_INTERRUPT_MASK
private static final int PENDING_INTERRUPT_MASK- See Also:
-
POSTPONED_JOB_INTERRUPT_MASK
private static final int POSTPONED_JOB_INTERRUPT_MASK- See Also:
-
TRAP_INTERRUPT_MASK
private static final int TRAP_INTERRUPT_MASK- See Also:
-
INTERRUPT_NONE
private static final int INTERRUPT_NONE- See Also:
-
INTERRUPT_IMMEDIATE
private static final int INTERRUPT_IMMEDIATE- See Also:
-
INTERRUPT_ON_BLOCKING
private static final int INTERRUPT_ON_BLOCKING- See Also:
-
INTERRUPT_NEVER
private static final int INTERRUPT_NEVER- See Also:
-
NULL_ARRAY
-
RUBY_THREAD_PREFIX
- See Also:
-
HandleInterruptVisitor
-
blockingIO
-
MUTEX_FOR_THREAD_EXCLUSIVE
- See Also:
-
currentBlockingTask
Deprecated.
-
-
Constructor Details
-
RubyThread
-
RubyThread
-
-
Method Details
-
executeInterrupts
-
postponedJobFlush
-
pendingInterruptActive
private boolean pendingInterruptActive() -
toKill
private void toKill() -
pendingInterruptClear
private void pendingInterruptClear() -
getInterrupts
private int getInterrupts() -
pendingInterruptDeque
-
pendingInterruptCheckMask
-
getErrorInfo
-
setErrorInfo
-
setContext
-
clearContext
public void clearContext() -
getContext
-
getNativeThread
-
setFiberCurrentThread
-
getFiberCurrentThread
-
beforeStart
public void beforeStart()Perform pre-execution tasks once the native thread is running, but we have not yet called the Ruby code for the thread. -
dispose
public void dispose()Dispose of the current thread by tidying up connections to other stuff -
createThreadClass
-
newInstance
Thread.newThread.new( [ arg ]* ) {| args | block } -> aThread
Creates a new thread to execute the instructions given in block, and begins running it. Any arguments passed to Thread.new are passed into the block.
x = Thread.new { sleep .1; print "x"; print "y"; print "z" } a = Thread.new { print "a"; print "b"; sleep .2; print "c" } x.join # Let the threads finish before a.join # main thread exits...produces: abxyzc -
start
Basically the same as Thread.new . However, if class Thread is subclassed, then calling start in that subclass will not invoke the subclass's initialize method. -
start19
Deprecated. -
adopt
-
adopt
-
adoptThread
private static RubyThread adoptThread(Ruby runtime, ThreadService service, RubyClass recv, Thread thread) -
initialize
-
startThread
private Thread startThread(ThreadContext context, Runnable runnable) throws RaiseException, OutOfMemoryError - Throws:
RaiseExceptionOutOfMemoryError
-
copyInterrupts
private static void copyInterrupts(ThreadContext context, Vector<RubyHash> sourceStack, Vector<RubyHash> targetStack) -
initThreadName
-
incAndGetThreadCount
-
startThread
private static RubyThread startThread(IRubyObject recv, IRubyObject[] args, boolean callInit, Block block) -
startWaiterThread
-
cleanTerminate
-
beDead
public void beDead() -
pollThreadEvents
public void pollThreadEvents() -
pollThreadEvents
Poll for thread events (raise, kill), propagating only events that are unmasked (seehandle_interrupt(ThreadContext, IRubyObject, IRubyObject, Block)or intended to fire before blocking operations if blocking = true.- Parameters:
context- the contextblocking- whether to trigger blocking operation interrupts
-
pollThreadEvents
-
blockingThreadPoll
-
anyInterrupted
private boolean anyInterrupted() -
throwThreadKill
private static void throwThreadKill() -
handle_interrupt
public static IRubyObject handle_interrupt(ThreadContext context, IRubyObject self, IRubyObject _mask, Block block) -
handleInterrupt
private IRubyObject handleInterrupt(ThreadContext context, RubyHash mask, BiFunction<ThreadContext, IRubyObject, IRubyObject> block) -
handleInterrupt
private <StateType> IRubyObject handleInterrupt(ThreadContext context, RubyHash mask, StateType state, BiFunction<ThreadContext, StateType, IRubyObject> block) -
checkInterruptMask
-
pending_interrupt_p
public static IRubyObject pending_interrupt_p(ThreadContext context, IRubyObject self, IRubyObject[] args) -
pending_interrupt_p
-
pendingInterruptInclude
-
setName
-
getName
-
current
-
main
-
pass
-
list
-
add_trace_func
-
add_trace_func
public static IRubyObject add_trace_func(ThreadContext context, IRubyObject recv, IRubyObject trace_func, Block block) -
set_trace_func
-
addToCorrectThreadGroup
-
getSymbolKey
-
getFiberLocals
-
getThreadLocals
-
getThreadLocals0
-
getContextVariables
- Specified by:
getContextVariablesin interfaceExecutionContext
-
isAlive
public boolean isAlive() -
isAdopted
public boolean isAdopted() -
fetch
-
fetch
-
op_aref
-
op_aref
Deprecated. -
op_aset
-
key_p
-
key_p
Deprecated. -
keys
-
thread_variable_p
-
thread_variable_get
-
thread_variable_set
-
thread_variables
-
isAbortOnException
public boolean isAbortOnException() -
setAbortOnException
public void setAbortOnException(boolean abortOnException) -
abort_on_exception
-
abort_on_exception_set
-
abort_on_exception
Returns the status of the global ``abort on exception'' condition. The default is false. When set to true, will cause all threads to abort (the process will exit(0)) if an exception is raised in any thread. See also Thread.abort_on_exception= . -
abort_on_exception_set
public static IRubyObject abort_on_exception_set(ThreadContext context, IRubyObject recv, IRubyObject value) -
abort_on_exception
Deprecated. -
abort_on_exception_x
Deprecated. -
abort_on_exception_set_x
Deprecated. -
alive_p
-
join
Deprecated. -
join
-
value
-
value
Deprecated. -
group
-
setThreadGroup
-
inspect
Description copied from class:RubyBasicObjectrb_obj_inspect call-seq: obj.inspect => string Returns a string containing a human-readable representation of obj. If not overridden, uses theto_smethod to generate the string. [ 1, 2, 3..4, 'five' ].inspect #=> "[1, 2, 3..4, \"five\"]" Time.new.inspect #=> "Wed Apr 09 08:54:39 CDT 2003"- Specified by:
inspectin interfaceIRubyObject- Overrides:
inspectin classRubyBasicObject- Returns:
- String
-
inspect
-
notEmpty
-
stop
-
kill
-
exit
-
stop_p
-
wakeup
-
priority
-
priority_set
-
javaPriorityToRubyPriority
public static int javaPriorityToRubyPriority(int javaPriority) -
rubyPriorityToJavaPriority
public static int rubyPriorityToJavaPriority(int rubyPriority) -
raise
Simplified utility method for just raising an existing exception in this thread.- Parameters:
exception- the exception to raise- Returns:
- this thread
-
raise
Simplified utility method for just raising an existing exception in this thread.- Parameters:
exception- the exception to raisemessage- the message to use- Returns:
- this thread
-
raise
-
raise
Deprecated. -
genericRaise
private IRubyObject genericRaise(ThreadContext context, RubyThread currentThread, IRubyObject... args) -
prepareRaiseException
-
run
-
sleep
Sleep the current thread for millis, waking up on any thread interrupts. We can never be sure if a wait will finish because of a Java "spurious wakeup". So if we explicitly wakeup and we wait less than requested amount we will return false. We will return true if we sleep right amount or less than right amount via spurious wakeup.- Parameters:
millis- Number of milliseconds to sleep. Zero sleeps forever.- Throws:
InterruptedException
-
status
-
status
-
getExitingException
- Returns:
- existing exception or null if terminated normally
-
executeBlockingTask
@Deprecated public void executeBlockingTask(RubyThread.BlockingTask task) throws InterruptedException Deprecated.- Throws:
InterruptedException
-
executeTaskBlocking
public <Data,Return> Return executeTaskBlocking(ThreadContext context, Data data, RubyThread.Task<Data, Return> task) throws InterruptedException- Throws:
InterruptedException
-
executeTask
public <Data,Return> Return executeTask(ThreadContext context, Data data, RubyThread.Task<Data, Return> task) throws InterruptedException- Throws:
InterruptedException
-
executeTaskBlocking
public <Data,Return> Return executeTaskBlocking(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task) throws InterruptedException- Throws:
InterruptedException
-
executeTask
public <Data,Return> Return executeTask(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task) throws InterruptedException- Throws:
InterruptedException
-
executeTask
private <Data,Return> Return executeTask(ThreadContext context, Data data, RubyThread.Status status, RubyThread.Task<Data, Return> task, boolean blocking) throws InterruptedException- Throws:
InterruptedException
-
executeReadWrite
public <Data> int executeReadWrite(ThreadContext context, Data data, byte[] bytes, int start, int length, RubyThread.ReadWrite<Data> task) throws InterruptedException Execute an interruptible read or write operation with the given byte range and data object.- Type Parameters:
Data- the type of the data object- Parameters:
context- the current contextdata- a data objectbytes- the bytes to writestart- start range of bytes to writelength- length of bytes to writetask- the write task- Returns:
- the number of bytes written
- Throws:
InterruptedException
-
enterSleep
public void enterSleep() -
exitSleep
public void exitSleep() -
getStatus
-
nativeStatus
-
kill
-
genericKill
-
pendingInterruptEnqueue
-
dieFromFinalizer
public void dieFromFinalizer()Used for finalizers that need to kill a Ruby thread. Finalizers run in a VM thread to which we do not want to attach a ThreadContext and within which we do not want to check for Ruby thread events. This mechanism goes directly to mail delivery, bypassing all Ruby Thread-related steps. -
safe_level
-
backtrace
-
backtrace
-
backtrace
-
backtraceInternal
private IRubyObject backtraceInternal(ThreadContext callerContext, IRubyObject level, IRubyObject length) -
backtrace_locations
-
backtrace_locations
-
backtrace_locations
public IRubyObject backtrace_locations(ThreadContext context, IRubyObject level, IRubyObject length) -
backtraceLocationsInternal
private IRubyObject backtraceLocationsInternal(ThreadContext callerContext, IRubyObject level, IRubyObject length) -
isReportOnException
public boolean isReportOnException() -
setReportOnException
public void setReportOnException(boolean reportOnException) -
report_on_exception_set
-
report_on_exception
-
report_on_exception_set
public static IRubyObject report_on_exception_set(ThreadContext context, IRubyObject self, IRubyObject state) -
report_on_exception
-
javaBacktrace
-
isCurrent
private boolean isCurrent() -
exceptionRaised
-
printReportExceptionWarning
protected void printReportExceptionWarning() -
exceptionRaised
For handling all exceptions bubbling out of threads- Parameters:
throwable-
-
abortOnException
-
mainThread
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.- Parameters:
io- the RubyIO that contains the channel, for managing blocked threads list.ops- the operations to wait for, from .- Returns:
- true if the IO's channel became ready for the requested operations, false if it was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.- Parameters:
io- the RubyIO that contains the channel, for managing blocked threads list.ops- the operations to wait for, from .timeout- a timeout in ms to limit the select. Less than zero selects forever, zero selects and returns ready channels or nothing immediately, and greater than zero selects for at most that many ms.- Returns:
- true if the IO's channel became ready for the requested operations, false if it timed out or was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations.- Parameters:
channel- the channel to perform a select against. If this is not a selectable channel, then this method will just return true.fptr- the fptr that contains the channel, for managing blocked threads list.ops- the operations to wait for, from .- Returns:
- true if the channel became ready for the requested operations, false if it was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations.- Parameters:
channel- the channel to perform a select against. If this is not a selectable channel, then this method will just return true.io- the RubyIO that contains the channel, for managing blocked threads list.ops- the operations to wait for, from .- Returns:
- true if the channel became ready for the requested operations, false if it was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.- Parameters:
channel- the channel to perform a select against. If this is not a selectable channel, then this method will just return true.io- the RubyIO that contains the channel, for managing blocked threads list.ops- the operations to wait for, from .timeout- a timeout in ms to limit the select. Less than zero selects forever, zero selects and returns ready channels or nothing immediately, and greater than zero selects for at most that many ms.- Returns:
- true if the channel became ready for the requested operations, false if it timed out or was not selectable.
-
select
Perform an interruptible select operation on the given channel and fptr, waiting for the requested operations or the given timeout.- Parameters:
channel- the channel to perform a select against. If this is not a selectable channel, then this method will just return true.fptr- the fptr that contains the channel, for managing blocked threads list.ops- the operations to wait for, from .timeout- a timeout in ms to limit the select. Less than zero selects forever, zero selects and returns ready channels or nothing immediately, and greater than zero selects for at most that many ms.- Returns:
- true if the channel became ready for the requested operations, false if it timed out or was not selectable.
-
interrupt
public void interrupt() -
setInterrupt
public void setInterrupt()Set the pending interrupt flag. CRuby: RB_VM_SET_INTERRUPT/ -
waitForIO
-
beforeBlockingCall
-
beforeBlockingCall
Deprecated. -
afterBlockingCall
public void afterBlockingCall() -
wait_timeout
- Throws:
InterruptedException
-
getThreadGroup
-
equals
Description copied from class:RubyObjectThis override does not do a "checked" dispatch.- Overrides:
equalsin classRubyObject- See Also:
-
hashCode
public int hashCode()Description copied from class:RubyObjectThis override does not do "checked" dispatch since Object usually has #hash defined.- Overrides:
hashCodein classRubyObject- See Also:
-
toString
Description copied from class:RubyObjectThe default toString method is just a wrapper that calls the Ruby "to_s" method.- Overrides:
toStringin classRubyObject
-
lock
Acquire the given lock, holding a reference to it for cleanup on thread termination.- Parameters:
lock- the lock to acquire, released on thread termination
-
lockInterruptibly
Acquire the given lock interruptibly, holding a reference to it for cleanup on thread termination.- Parameters:
lock- the lock to acquire, released on thread termination- Throws:
InterruptedException- if the lock acquisition is interrupted
-
tryLock
Try to acquire the given lock, adding it to a list of held locks for cleanup on thread termination if it is acquired. Return immediately if the lock cannot be acquired.- Parameters:
lock- the lock to acquire, released on thread termination
-
unlock
Release the given lock and remove it from the list of locks to be released on thread termination.- Parameters:
lock- the lock to release and dereferences
-
unlockAll
public void unlockAll()Release all locks held. -
sleep
Release lock and sleep.- Throws:
InterruptedException
-
sleep
Release lock and sleep for the specified number of milliseconds.- Throws:
InterruptedException
-
identityString
-
uninterruptible
public static <StateType> IRubyObject uninterruptible(ThreadContext context, StateType state, BiFunction<ThreadContext, StateType, IRubyObject> f) Run the providedBiFunctionwithout allowing for any cross-thread interrupts (equivalent to callinghandle_interrupt(ThreadContext, IRubyObject, IRubyObject, Block)with Object => :never. MRI: rb_uninterruptible- Parameters:
context- the current contextf- the bifunction to execute- Returns:
- return value of f.apply.
-
exclusive
@Deprecated public static IRubyObject exclusive(ThreadContext context, IRubyObject recv, Block block) Deprecated. -
getMutexForThreadExclusive
-
internalRaise
Deprecated.This is intended to be used to raise exceptions in Ruby threads from non- Ruby threads like Timeout's thread.- Parameters:
args- Same args as for Thread#raise
-
receiveMail
Deprecated. -
checkMail
Deprecated. -
selectForAccept
Deprecated. -
backtrace20
Deprecated. -
backtrace
Deprecated. -
backtrace_locations
Deprecated. -
pass
Deprecated.
-