java.lang.Object
simula.runtime.RTS_Coroutine
- All Implemented Interfaces:
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/MainLink to GitHub: Source File.
- Author:
- Øystein Myhre Andersen
-
Field Summary
Modifier and TypeFieldDescriptionstatic RuntimeException
Used to propagate exceptions to caller.private RTS_Coroutine
The callerprivate Thread
The caller threadprivate static RTS_Coroutine
The current Coroutineprivate boolean
True if all actions are done.private static Semaphore
Semaphore used to suspend/resume main (platform) Threadprivate Semaphore
Semaphore used to suspend/resume this coroutine's Threadprivate Runnable
The runnable targetprivate Thread
The target thread(package private) Thread.UncaughtExceptionHandler
The UncaughtExceptionHandler. -
Constructor Summary
ConstructorDescriptionRTS_Coroutine
(Runnable target) Create a new Coroutine with the given target. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
detach()
Detach this Coroutine.static RTS_Coroutine
Returns the current Coroutine.boolean
isDone()
Returns true if target is terminated.private static void
resume
(RTS_Coroutine coroutine) Resume the given Coroutinefinal void
run()
Start or resume this Coroutine.private static void
suspend
(RTS_Coroutine coroutine) Suspend the given CoroutinetoString()
-
Field Details
-
current
The current Coroutine -
caller
The caller -
done
private boolean doneTrue if all actions are done. -
target
The runnable target -
targetThread
The target thread -
callerThread
The caller thread -
mainSemaphore
Semaphore used to suspend/resume main (platform) Thread -
semaphore
Semaphore used to suspend/resume this coroutine's Thread -
_PENDING_EXCEPTION
Used to propagate exceptions to caller. -
uncaughtExceptionHandler
Thread.UncaughtExceptionHandler uncaughtExceptionHandlerThe UncaughtExceptionHandler.
-
-
Constructor Details
-
RTS_Coroutine
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
Returns the current Coroutine.- Returns:
- the current Coroutine
-
run
public final void run()Start or resume this Coroutine. -
detach
public static void detach()Detach this Coroutine. -
suspend
Suspend the given Coroutine- Parameters:
coroutine
- the given Coroutine
-
resume
Resume the given Coroutine- Parameters:
coroutine
- the given Coroutine
-
toString
-