Skip to content

Document lock and ownership contracts - #76

Merged
benoitc merged 1 commit into
mainfrom
lock-contracts
Aug 29, 2026
Merged

Document lock and ownership contracts#76
benoitc merged 1 commit into
mainfrom
lock-contracts

Conversation

@benoitc

@benoitc benoitc commented Aug 29, 2026

Copy link
Copy Markdown
Owner

The struct comments are where a reader decides whether a change is safe, and the one on py_context_t described a design that no longer exists. This rewrites it as the contract the code follows today: one context thread runs Python, NIFs only enqueue, queue_mutex before req->mutex, interrupt_mutex never with a GIL held, the request mirror and msg_env touched by the context thread only, and the join-or-leak rule on shutdown. erlang_event_loop_t gets the same for its four mutexes and the interpreter detach handshake. On the Erlang side py_context's moduledoc caught up with the callback pipe, and the modules owning a resource open with what they own, who they talk to and what they never do.

The py_context_t header still described dirty-scheduler execution
over a shared-GIL pool. It now says which thread owns each field
group, what each mutex guards, the lock order, and why a stuck
context is leaked rather than freed. The event loop struct gets the
same treatment, and the Erlang modules that own a resource state in
three lines what they own, who they talk to and what they never do.
@benoitc
benoitc merged commit 20705f7 into main Aug 29, 2026
20 checks passed
@benoitc
benoitc deleted the lock-contracts branch August 29, 2026 14:15
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