Skip to content

Add thread-safety to _CounterMeta class creation counter#13

Draft
Copilot wants to merge 3 commits intofix-jax-class-comparison-9360936800683187626from
copilot/sub-pr-3
Draft

Add thread-safety to _CounterMeta class creation counter#13
Copilot wants to merge 3 commits intofix-jax-class-comparison-9360936800683187626from
copilot/sub-pr-3

Conversation

Copy link

Copilot AI commented Feb 13, 2026

The _class_creation_counter in _CounterMeta was susceptible to race conditions during concurrent class creation, potentially causing duplicate _class_id values.

Changes

  • Thread-safe counter increment: Wrap _class_id assignment and counter increment in threading.Lock to ensure atomicity
  • Verification test: Add test_thread_safe_class_creation() that creates 100 classes across 10 concurrent threads and validates unique IDs
class _CounterMeta(abc.ABCMeta):
    _class_creation_counter: int = 0
    _counter_lock: threading.Lock = threading.Lock()

    def __init__(cls, name, bases, dct):
        super().__init__(name, bases, dct)
        with _CounterMeta._counter_lock:
            cls._class_id = _CounterMeta._class_creation_counter
            _CounterMeta._class_creation_counter += 1

Addresses feedback on PR #3.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits February 13, 2026 08:00
Co-authored-by: igor-holt <125706350+igor-holt@users.noreply.github.com>
Co-authored-by: igor-holt <125706350+igor-holt@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix JAX uniqueness class comparison stability Add thread-safety to _CounterMeta class creation counter Feb 13, 2026
Copilot AI requested a review from igor-holt February 13, 2026 08:04
Copy link
Owner

@igor-holt igor-holt left a comment

Choose a reason for hiding this comment

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

Send

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