/** Dispose of the current thread by tidying up connections to other stuff */
  public void dispose() {
    if (disposed) return;

    synchronized (this) {
      if (disposed) return;

      disposed = true;

      // remove from parent thread group
      threadGroup.remove(this);

      // unlock all locked locks
      unlockAll();

      // reset thread priority to initial if pooling
      if (Options.THREADPOOL_ENABLED.load()) {
        threadImpl.setPriority(initialPriority);
      }

      // mark thread as DEAD
      beDead();
    }

    // unregister from runtime's ThreadService
    getRuntime().getThreadService().unregisterThread(this);
  }
Example #2
0
 private void addToCorrectThreadGroup(ThreadContext context) {
   // JRUBY-3568, inherit threadgroup or use default
   IRubyObject group = context.getThread().group();
   if (!group.isNil()) {
     ((RubyThreadGroup) group).addDirectly(this);
   } else {
     context.runtime.getDefaultThreadGroup().addDirectly(this);
   }
 }