Module Simula

Class RTS_Coroutine

java.lang.Object
simula.runtime.RTS_Coroutine
All Implemented Interfaces:
Runnable

public class RTS_Coroutine extends Object implements Runnable
Utility class Coroutine.
  Implementing Coroutines using Virtual Threads and Semaphores

  public class Coroutine implements Runnable {
      public Coroutine(Runnable target)
                public static Coroutine getCurrentCoroutine()
      public final void run()
      public static void detach()
      public boolean isDone()
      ....
  }
 
  More info: https://wiki.openjdk.java.net/display/loom/Main
 
Link to GitHub: Source File.
Author:
Øystein Myhre Andersen
  • Field Details

    • current

      private static RTS_Coroutine current
      The current Coroutine
    • caller

      private RTS_Coroutine caller
      The caller
    • done

      private boolean done
      True if all actions are done.
    • target

      private Runnable target
      The runnable target
    • targetThread

      private Thread targetThread
      The target thread
    • callerThread

      private Thread callerThread
      The caller thread
    • mainSemaphore

      private static Semaphore mainSemaphore
      Semaphore used to suspend/resume main (platform) Thread
    • semaphore

      private Semaphore semaphore
      Semaphore used to suspend/resume this coroutine's Thread
    • _PENDING_EXCEPTION

      public static RuntimeException _PENDING_EXCEPTION
      Used to propagate exceptions to caller.
    • uncaughtExceptionHandler

      Thread.UncaughtExceptionHandler uncaughtExceptionHandler
      The UncaughtExceptionHandler.
  • Constructor Details

    • RTS_Coroutine

      public RTS_Coroutine(Runnable target)
      Create a new Coroutine with the given target.
      Parameters:
      target - a runnable target
  • Method Details

    • isDone

      public boolean isDone()
      Returns true if target is terminated.
      Returns:
      true if target is terminated
    • getCurrentCoroutine

      public static RTS_Coroutine getCurrentCoroutine()
      Returns the current Coroutine.
      Returns:
      the current Coroutine
    • run

      public final void run()
      Start or resume this Coroutine.
      Specified by:
      run in interface Runnable
    • detach

      public static void detach()
      Detach this Coroutine.
    • suspend

      private static void suspend(RTS_Coroutine coroutine)
      Suspend the given Coroutine
      Parameters:
      coroutine - the given Coroutine
    • resume

      private static void resume(RTS_Coroutine coroutine)
      Resume the given Coroutine
      Parameters:
      coroutine - the given Coroutine
    • toString

      public String toString()
      Overrides:
      toString in class Object