Skip to content

Conversation

@jserv
Copy link
Contributor

@jserv jserv commented Jan 8, 2026

This addresses reliability issue in JIT parallel mode by fixing race conditions in the T2C.

  • Add portable ATOMIC_* macros in common.h with GNU __atomic builtins as primary, C11 stdatomic fallback, and single-threaded fallback
  • Replace busy-wait polling with proper pthread_cond_wait in t2c_runloop
  • Change queue_entry_t from block pointer to cache key (PC|SATP) to prevent use-after-free when blocks are evicted during compilation
  • Add defensive check in t2c_compile to skip already-compiled blocks
  • Use atomic operations for shared block fields
  • Proper shutdown sequence: signal under lock, join, cleanup queue

Summary by cubic

Fixes T2C JIT race conditions to make background compilation reliable and thread-safe. Replaces busy-waiting with condition variables, adds portable atomics, and prevents use-after-free in the compile queue.

  • Bug Fixes

    • Replace busy-wait polling with pthread_cond_wait in t2c_runloop; signal on enqueue and during shutdown.
    • Add portable ATOMIC_* macros and use them for shared fields (hot2, compiled, n_invoke, is_interrupted) with acquire/release ordering.
    • Queue cache keys (PC | SATP) instead of block pointers to avoid use-after-free; look up and compile under the cache lock only if the block still exists.
    • Defensive checks to skip already-compiled blocks and atomic increment of n_invoke when T2C is enabled.
  • Dependencies

    • Build with gnu11 instead of gnu99 to support the atomics fallback path.

Written for commit c2c6847. Summary will update on new commits.

This addresses reliability issue in JIT parallel mode by fixing race
conditions in the T2C.
- Add portable ATOMIC_* macros in common.h with GNU __atomic builtins
  as primary, C11 stdatomic fallback, and single-threaded fallback
- Replace busy-wait polling with proper pthread_cond_wait in t2c_runloop
- Change queue_entry_t from block pointer to cache key (PC|SATP) to
  prevent use-after-free when blocks are evicted during compilation
- Add defensive check in t2c_compile to skip already-compiled blocks
- Use atomic operations for shared block fields
- Proper shutdown sequence: signal under lock, join, cleanup queue
@jserv jserv added this to the release-2026.1 milestone Jan 8, 2026
Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 7 files

Copy link
Contributor Author

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Benchmarks

Details
Benchmark suite Current: c2c6847 Previous: 7dad667 Ratio
Dhrystone 1657.333 DMIPS 1657 DMIPS 1.00
CoreMark 1025.5 iterations/sec 1017.224 iterations/sec 0.99

This comment was automatically generated by workflow using github-action-benchmark.

@jserv jserv merged commit b9c0707 into master Jan 8, 2026
23 checks passed
@jserv jserv deleted the refine-jit branch January 8, 2026 10:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants