Repository navigation
README: a barrier built from pt_wait() and pt_broadcast(), with a test - #30
Open
LarryRuane wants to merge 3 commits into
Open
LarryRuane wants to merge 3 commits into
LarryRuane wants to merge 3 commits into
Conversation
With n of 2 it's a rendezvous. The waiters test a generation number, because the last to arrive keeps running and may start the next round before they run; a waiter testing the count would see that round and sleep forever. Checked against the library: the generation version passes five rounds of three threads, and the count version hangs after the first opening. TODO keeps the countdown latch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SR7v9BVsFrHiEhQBSqZmAs
The barrier from README.md as a nested protothread function: three threads, five rounds, staggered so the last to arrive changes, checking that nobody passes early or gets more than a round ahead. Then two threads exchanging a value each round through a barrier of 2. The exchange needs two sets of slots, alternated by round. With one, the thread that keeps running writes its next value before the other has read this one; the README now says so. Mutations checked: one slot fails the exchange check, and waiters testing the count instead of the generation leave the threads stuck. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SR7v9BVsFrHiEhQBSqZmAs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SR7v9BVsFrHiEhQBSqZmAs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds an "Example - a barrier" section after "Wait channels". It shows a barrier for n protothreads, which with n of 2 is a rendezvous, in about a dozen lines on top of
pt_wait()andpt_broadcast(). Waiters test a generation number, not the count. The last to arrive keeps running, and may arrive for the next round before the waiters it just woke get to run. A waiter testing the count would see that round and could wait forever. The README walks through the sequence, and why wrappinggenis harmless. Two threads can also swap data through it, but if they meet repeatedly they need two sets of slots, used in alternate rounds. The README now says that too.The test suite gets a
barriersection that uses the README code as a nested protothread function. Three threads go through five staggered rounds, and two threads exchange a value each round. Breaking either point (waiters testing the count, or a single slot) makes the test fail.TODO's "Barrier and countdown latch" entry is now just the latch, since the README now shows a barrier.
🤖 Generated with Claude Code
https://claude.ai/code/session_01SR7v9BVsFrHiEhQBSqZmAs