wip(0.S3): packages and examples migrated again from their pre-0.S sources in one run

ludic migrate state packages <every example program> packages/ludic.lab/example/plate.ludic
  1804 vars into 126 states, 64 into lets; 23498 edits in 460 files

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Orkun ÇAKILKAYA 2026-09-25 15:31:34 +03:00
parent 5ffe50ed02
commit 19fcf60599
459 changed files with 17862 additions and 17603 deletions

View file

@ -6,25 +6,27 @@
program Threads {
const N: int = 20000
var calls: int = 0 # an atomic handle, made on the main thread before any work
var lock: int = 0 # a mutex handle
var total: long = 0 # guarded by `lock`
state ThreadsState {
calls: int = 0 # an atomic handle, made on the main thread before any work
lock: int = 0 # a mutex handle
total: long = 0 # guarded by `lock`
}
# out[i] = i * i: every index written exactly once, by whichever thread claimed it
function square(i: int, out: words) -> void { out[i] = i * i }
# count the call atomically, and add i to a shared total under the mutex
function tally(i: int, ctx: pointer) -> void {
Sync.add(calls, 1)
Sync.lock(lock)
total = total + i
Sync.unlock(lock)
function tally(threads_st: mut ThreadsState, i: int, ctx: pointer) -> void {
Sync.add(threads_st.calls, 1)
Sync.lock(threads_st.lock)
threads_st.total = threads_st.total + i
Sync.unlock(threads_st.lock)
}
# remember which calls ran on a pool thread
function placed(i: int, out: words) -> void { if Job.is_worker() { out[i] = 1 } else { out[i] = 0 } }
entry {
entry (threads_st: mut ThreadsState) {
if Sync.cpu_count() >= 1 { print(1) }
if not Job.is_worker() { print(2) }
@ -34,12 +36,12 @@ program Threads {
for i in 0 .. N { if sq[i] != i * i { right = false } }
if right { print(3) }
calls = Sync.atomic()
lock = Sync.mutex()
threads_st.calls = Sync.atomic()
threads_st.lock = Sync.mutex()
Job.parallel_for(N, fn tally, null)
if Sync.get(calls) == N { print(4) }
if Sync.get(threads_st.calls) == N { print(4) }
let want: long = N * (N - 1) / 2
if total == want { print(5) }
if threads_st.total == want { print(5) }
let ran = words(N)
Job.parallel_for(N, fn placed, ran)