Package kilim

Class Task<TT>

    • Field Detail

      • id

        public final int id
        Task id, automatically generated
      • idSource

        static final java.util.concurrent.atomic.AtomicInteger idSource
      • fiber

        protected Fiber fiber
        The stack manager in charge of rewinding and unwinding the stack when Task.pause() is called.
      • pauseReason

        protected PauseReason pauseReason
        The reason for pausing (duh) and performs the role of a await condition in CCS. This object is responsible for resuming the task.
        See Also:
        PauseReason
      • running

        protected java.util.concurrent.atomic.AtomicBoolean running
        running = true when it is put on the schdulers run Q (by Task.resume()). The Task.runExecute() method is called at some point; 'running' remains true until the end of runExecute (where it is reset), at which point a fresh decision is made whether the task needs to continue running.
      • done

        protected volatile boolean done
      • preferredResumeThread

        volatile int preferredResumeThread
        The thread in which to resume this task. Ideally, we shouldn't have any preferences, but using locks in pausable methods will require the task to be pinned to a thread.
        See Also:
        ReentrantLock
      • tid

        private int tid
      • scheduler

        protected Scheduler scheduler
        The object responsible for handing this task to a thread when the task is runnable.
      • exitResult

        public volatile java.lang.Object exitResult
      • timer

        public Timer timer
      • debugRunning

        private static boolean debugRunning
    • Constructor Detail

      • Task

        public Task()
      • Task

        Task​(boolean dummy)
    • Method Detail

      • id

        public int id()
      • getScheduler

        public Scheduler getScheduler()
      • start

        public Task<TT> start()
        Used to start the task; the task doesn't resume on its own. Custom schedulers must be set (@see #setScheduler(Scheduler)) before start() is called.
        Returns:
      • skipInvoke

        private static boolean skipInvoke​(java.lang.String klass,
                                          java.lang.String name)
      • getStackDepth

        public static int getStackDepth​(Task task)
        The generated code calls Fiber.upEx, which in turn calls this to find out out where the current method is w.r.t the closest _runExecute method.
        Returns:
        the number of stack frames above _runExecute(), not including this method
      • checkTimeout

        boolean checkTimeout()
      • getExecutionThread

        public java.lang.Thread getExecutionThread()
      • resume

        public boolean resume()
        Add itself to scheduler if it is neither already running nor done.
        Returns:
        True if it scheduled itself.
      • getCurrentTask

        public static Task getCurrentTask()
                                   throws Pausable
        This is a placeholder that doesn't do anything useful. Weave replaces the call in the bytecode from invokestateic Task.getCurrentTask to load fiber getfield task
        Throws:
        Pausable
      • exit

        public static void exit​(java.lang.Object aExitValue)
                         throws Pausable
        Analogous to System.exit, except an Object can be used as the exit value
        Throws:
        Pausable
      • exit

        public static void exit​(java.lang.Object aExitValue,
                                Fiber f)
      • errorExit

        public static void errorExit​(java.lang.Throwable ex)
                              throws Pausable
        Exit the task with a throwable indicating an error condition. The value is conveyed through the exit mailslot (see informOnExit). All exceptions trapped by the task scheduler also set the error result.
        Throws:
        Pausable
      • errorExit

        public static void errorExit​(java.lang.Throwable ex,
                                     Fiber f)
      • errNotWoven

        public static void errNotWoven()
      • errNotWoven

        public static void errNotWoven​(Task t)
      • invoke

        public static java.lang.Object invoke​(java.lang.reflect.Method method,
                                              java.lang.Object obj,
                                              java.lang.Object... args)
                                       throws Pausable,
                                              java.lang.IllegalAccessException,
                                              java.lang.IllegalArgumentException,
                                              java.lang.reflect.InvocationTargetException
        Invoke a pausable method via reflection. Equivalent to Method.invoke().
        Parameters:
        method - : The method to be invoked. (Implementation note: the corresponding woven method is invoked instead).
        obj - : The object on which the method is invoked. Can be null if the method is static.
        args - : Arguments to the method
        Returns:
        Throws:
        Pausable
        java.lang.IllegalAccessException
        java.lang.IllegalArgumentException
        java.lang.reflect.InvocationTargetException
      • getWovenMethod

        private static java.lang.reflect.Method getWovenMethod​(java.lang.reflect.Method m)
      • sleep

        public static void sleep​(long millis)
                          throws Pausable
        Parameters:
        millis - to sleep. Like thread.sleep, except it doesn't throw an interrupt, and it doesn't hog the java thread.
        Throws:
        Pausable
      • shutdown

        public static void shutdown()
      • yield

        public static void yield()
                          throws Pausable
        Yield cooperatively to the next task waiting to use the thread.
        Throws:
        Pausable
      • yield

        public static void yield​(Fiber f)
      • pause

        public static void pause​(PauseReason pauseReason)
                          throws Pausable
        Ask the current task to pause with a reason object, that is responsible for resuming the task when the reason (for pausing) is not valid any more.
        Parameters:
        pauseReason - the reason
        Throws:
        Pausable
      • execute

        public void execute​(Fiber f)
                     throws java.lang.Exception
        Specified by:
        execute in interface Fiber.Worker
        Throws:
        java.lang.Exception
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • dump

        public java.lang.String dump()
      • checkPin

        void checkPin()
      • pinToThread

        public void pinToThread()
      • unpinFromThread

        public void unpinFromThread()
      • setPauseReason

        protected final void setPauseReason​(PauseReason pr)
      • getPauseReason

        public final PauseReason getPauseReason()
      • isDone

        public boolean isDone()
      • setTid

        protected void setTid​(int tid)
      • getTid

        public int getTid()
        return the thread ID that the task is currently running on, valid only during execute
      • run

        public void run()
                 throws NotPausable
        Called by WorkerThread, it is the wrapper that performs pre and post execute processing (in addition to calling the execute(fiber) method of the task.
        Specified by:
        run in interface java.lang.Runnable
        Throws:
        NotPausable
      • equals

        public boolean equals​(java.lang.Object obj)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • checkKill

        public void checkKill()
      • getState

        public boolean getState()
      • fork

        public static Task fork​(Pausable.Fork body)
        Wraps the given object or lambda expression in a Task and starts that task. Beware of inadvertent sharing when multiple lambdas are created in the same context
        Parameters:
        body - the lambda to delegate to
        Returns:
        the spawned task.
      • spawn

        public static <TT> Task.Spawn<TT> spawn​(Pausable.Spawn<TT> body)
        Wraps the given object or lambda expression in a Task and starts that task. Beware of inadvertent sharing when multiple lambdas are created in the same context
        Parameters:
        body - the lambda to delegate to
        Returns:
        the spawned task.
      • spawn

        public static Task.Invoke spawn​(java.lang.reflect.Method method,
                                        java.lang.Object obj,
                                        java.lang.Object... args)
      • idledown

        public static void idledown()
        idledown the default scheduler
        See Also:
        Scheduler.idledown()