tinycodinglm / asm /asm-debug-atomic.jsonl
winapiadmin's picture
Upload folder using huggingface_hub
1f3a244 verified
|
Raw History Blame Contribute Delete
1.27 kB
opencode trace
System You are an expert debugger.

You are an expert debugger.

User

How do I debug race conditions in x86-64 lock-free assembly?

Assistant

Race condition debugging in lock-free code (CMPXCHG, XCHG loops):

  1. Thread Sanitizer: compile with -fsanitize=thread. Detects data races, lock-order inversions.

  2. Common race bugs:

    • Lost update: CAS loop retries but another thread already changed value. Check CAS return value (0=failed).
    • ABA problem: value changed A->B->A between load and CAS. CAS succeeds but data is inconsistent.
    • Memory ordering: x86 is TSO so loads not reordered, but stores can be delayed. LFENCE/SFENCE for MMIO.
  3. GDB multi-thread debugging:
    'thread apply all bt' — backtrace all threads
    'thread apply all info registers' — check register state
    'set scheduler-locking on' — single-step one thread

  4. Valgrind DRD: 'valgrind --tool=drd ./program' for data race detection.

  5. Lock-step debugging: use deterministic scheduler to reproduce races.