It is obvious that the above mentioned insertion mechanism
is not interrupt-safe. An interrupt occurring during or
after step (1) and entailing overlapped execution of the same
sequence on the same data structure results in an inconsistent
state. After step (1) the tail pointer still points to the old
last element which, through step (1), became the predecessor
of the inserted element. Overlapped execution of the insertion
procedure destroys that predecessor relationship and
creates a new one: the old last element now points to the element
inserted during the interruption phase. At the end of
this phase, the tail pointer will point to the most recently inserted
element. After return from interrupt, resumed execution
of step (2) then lets the tail pointer point to the element
that was going to be placed on the queue but whose insertion
was interrupted. The effect is that that element, and any
other element enqueued afterwards, will never be found on
the queue when following the head pointer. A dequeue typically
employs the head pointer to remove the next element
from the (FIFO) queue. Consequently, due to overlapping
enqueue operations, elements may be lost.