Class ExecutionSequencer.ThreadConfinedTaskQueue

  • Enclosing class:
    ExecutionSequencer

    private static final class ExecutionSequencer.ThreadConfinedTaskQueue
    extends java.lang.Object
    This object is unsafely published, but avoids problematic races by relying exclusively on the identity equality of its Thread field so that the task field is only accessed by a single thread.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) java.util.concurrent.Executor nextExecutor
      Only used by the thread associated with this object
      (package private) java.lang.Runnable nextTask
      Only used by the thread associated with this object
      (package private) java.lang.Thread thread
      This field is only used for identity comparisons with the current thread.
    • Method Summary

      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • thread

        @CheckForNull
        java.lang.Thread thread
        This field is only used for identity comparisons with the current thread. Field assignments are atomic, but do not provide happens-before ordering; however:
        • If this field's value == currentThread, we know that it's up to date, because write operations in a thread always happen-before subsequent read operations in the same thread
        • If this field's value == null because of unsafe publication, we know that it isn't the object associated with our thread, because if it was the publication wouldn't have been unsafe and we'd have seen our thread as the value. This state is also why a new ThreadConfinedTaskQueue object must be created for each inline execution, because observing a null thread does not mean the object is safe to reuse.
        • If this field's value is some other thread object, we know that it's not our thread.
        • If this field's value == null because it originally belonged to another thread and that thread cleared it, we still know that it's not associated with our thread
        • If this field's value == null because it was associated with our thread and was cleared, we know that we're not executing inline any more
        All the states where thread != currentThread are identical for our purposes, and so even though it's racy, we don't care which of those values we get, so no need to synchronize.
      • nextTask

        @CheckForNull
        java.lang.Runnable nextTask
        Only used by the thread associated with this object
      • nextExecutor

        @CheckForNull
        java.util.concurrent.Executor nextExecutor
        Only used by the thread associated with this object
    • Constructor Detail

      • ThreadConfinedTaskQueue

        private ThreadConfinedTaskQueue()