x86 rep instructions, lock prefix, atomics and real-time

Viewed 51

Consider the following case:

  • Thread A (evil code I do not control):
# Repeat some string operation for an arbitrarily long time
lock rep stosq ...
  • Thread 2 (my code, should have lock-free behaviour):
# some simple atomic operation involving a `lock` prefix
# on the beginning of the data processed by the repeating instruction
lock cmpxchg ...

Can I assume that the lock held by rep stosq will be for each individual element, and not for the instruction's execution as a whole ? Otherwise doesn't that mean that every code which should have real-time semantics (no loops, no syscalls, total functions, every operation terminates in a finite time, etc) can still be broken just by having some "evil" code in another thread doing such a thing, which would block the cmpxchg on the other thread for an abritrarily long time?

0 Answers
Related