Skip to content

Fix pthread_t aliasing with pthread_create - #15

Open
maxwellpirtle wants to merge 1 commit into
mcminickpt:mainfrom
maxwellpirtle:pthread-aliasing
Open

Fix pthread_t aliasing with pthread_create#15
maxwellpirtle wants to merge 1 commit into
mcminickpt:mainfrom
maxwellpirtle:pthread-aliasing

Conversation

@maxwellpirtle

@maxwellpirtle maxwellpirtle commented Aug 3, 2026

Copy link
Copy Markdown
Contributor

Overview

As we discussed, I was worried about the possibility of pthread_t confusing the model. Simply using the runner_id_t assigned uniquely to each thread is a better strategy here and we can avoid using the pthread_t handles altogether in the model (which is a better design anyway).

Summary by CodeRabbit

  • New Features

    • Added a recycled-thread example demonstrating repeated worker-thread creation and cleanup.
    • Updated example applications to link with the library.
  • Bug Fixes

    • Improved thread tracking when thread descriptors are reused.
    • Thread creation now validates and propagates stable runner IDs, improving scheduling and checkpoint restoration reliability.
    • Runner observations now consistently use model-assigned IDs.

@maxwellpirtle maxwellpirtle self-assigned this Aug 3, 2026
@coderabbitai

coderabbitai Bot commented Aug 3, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: fa0fbbec-1c41-41a8-90ea-7804bae170e7

📥 Commits

Reviewing files that changed from the base of the PR and between 7a2d504 and 05fd24b.

📒 Files selected for processing (7)
  • include/mcmini/coordinator/model_to_system_map.hpp
  • src/examples/CMakeLists.txt
  • src/examples/recycled-thread.c
  • src/lib/wrappers.c
  • src/mcmini/coordinator/coordinator.cpp
  • src/mcmini/mcmini.cpp
  • src/mcmini/model/transitions/thread.cpp

📝 Walkthrough

Walkthrough

The change replaces pthread_t-address runner identification with model-assigned runner IDs. Thread wrappers publish IDs to the scheduler, coordinator observation validates them, and a recycled-thread example demonstrates repeated thread creation.

Changes

Runner ID observation flow

Layer / File(s) Summary
Runner observation contract
include/mcmini/coordinator/model_to_system_map.hpp, src/mcmini/coordinator/coordinator.cpp
Runner observation now accepts runner IDs, returns void, removes address-based lookup, and raises an error when model and target IDs differ.
Thread runner ID propagation
src/lib/wrappers.c, src/mcmini/mcmini.cpp, src/mcmini/model/transitions/thread.cpp
Thread creation arguments carry the child runner ID. The wrapper publishes and validates the ID before sending it to the scheduler.
Recycled-thread example
src/examples/CMakeLists.txt, src/examples/recycled-thread.c
The build adds the recycled-thread executable and links the examples with libmcmini. The example creates and joins threads across three rounds.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant ThreadWrapper
  participant Scheduler
  participant Coordinator
  ThreadWrapper->>ThreadWrapper: Publish child runner ID
  ThreadWrapper->>Scheduler: Send runner ID
  Scheduler->>Coordinator: Observe runner
  Coordinator->>Coordinator: Validate runner ID
Loading

Possibly related PRs

Suggested labels: bug

Suggested reviewers: gc00, aayushi363

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the primary change: replacing unsafe pthread_t handling in pthread_create with runner IDs.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant