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.