Repository navigation
MessageQueue<T>: a one-way queue between threads (Worker step 1) - #80
Merged
Merged
Conversation
MessageQueue<T> (push, take with an optional timeout, close, clear, closed, length) keeps its items in a TypeScript array guarded by a lock taken with Atomics.compareExchange; a taker sleeps in Atomics.wait. So the collector sees queued items under -mm=gc, Shared.share keeps their counts atomic under -mm=rc, and under -mm=own a push moves the item in and take moves it out. tests/message_queue.ts: two threads pass 10 000 numbers, strings and class instances through it in order, both ways for the objects, plus timeout, close and clear. Passes under gc, rc, none and own, release, compiled and under the JIT; debug was not built locally. docs/worker-design.md records what this settled: objects go through under own without Shared<T>, a push is a move, and the open point for step 2 - under own a handler stored in the Worker can't capture a local used again afterwards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What
Step 1 of
docs/worker-design.md:MessageQueue<T>, the one-way queue between threads thatWorkerwill be built on.MessageQueue<T>insrc/generics/lib.generics.ts, afterThread, withpush,take(timeout?),close(),clear(),closedandlength.Atomics.compareExchange. A thread waiting for an item sleeps inAtomics.waitrather than spinning.-mm=gcthe collector sees queued items.-mm=rc,Shared.sharemakes their counts atomic. It marks every block the value reaches, so a message's fields are covered too.-mm=own, a push moves the item in andtakemoves it out.constShared<MessageQueue<T>>that each function captures, the same way the thread tests share anInt32Array.Tests
tests/message_queue.ts:close(), a push after closing, andclear().Run locally in release under
gc,rc,noneandown, both compiled and under the JIT, all passing. The compiled test passed 8 runs out of 8 per model.thread_spawn,thread_move,atomics_waitandatomicsstill pass under all four.Not run locally: the debug configuration. This machine's compiler debug runtime is older than
tslang(it has no__tslang_heap_shared), so the debug library doesn't build here. CI is the first debug run.Design doc updates
docs/worker-design.mdnow records what step 1 settled for-mm=own:Shared<T>.Workercan't capture a local that's used again afterwards. That is a compile error underown, so handler state needs aShared<T>, or the program usesreceive()instead.🤖 Generated with Claude Code