A system and method for ensuring non-interfering garbage collection in a
real time multi-threaded environment. An incarnation counter is
associated with a scoped memory area. The incarnation counter is
atomically updated upon access by a no heap thread not interruptible by
garbage collection operations. A write stub is identified and includes
instructions to store data into storage locations of the scoped memory
area. The instructions are dynamically modified to interrupt execution of
a garbage collection thread. A garbage collection thread is executed over
the scoped memory area. At least one of a read from the scoped memory
area and a write to the scoped memory area are attempted. For the read
attempt, an incarnation number is read from the incarnation counter of
the scoped memory area and is locally stored. A value from a storage
location in the scoped memory area is loaded and the incarnation number
is reread. The reread incarnation number is compared with the locally
stored incarnation number. The garbage collection thread is interrupted
when the reread and locally stored incarnation numbers fail to match. For
the write attempt, the instructions in the write stub are executed. The
instructions include one of storing data into one such location in the
scoped memory area and interrupting execution of the garbage collection
thread.