aboutsummaryrefslogtreecommitdiff
path: root/shared_counter.kpl
diff options
context:
space:
mode:
authornodist <kevin.comas.git@gmail.com>2026-08-02 11:07:19 -0400
committernodist <kevin.comas.git@gmail.com>2026-08-02 11:07:19 -0400
commit651cec72681afc0821a03a71d07aaa797d37649e (patch)
tree3a5a1689057052ad0fefcebac5ed8b651e5a56b4 /shared_counter.kpl
parentc9d9511e6c964853e35f143cf45f3a0f02521e1d (diff)
new syntax
Diffstat (limited to 'shared_counter.kpl')
-rw-r--r--shared_counter.kpl57
1 files changed, 0 insertions, 57 deletions
diff --git a/shared_counter.kpl b/shared_counter.kpl
deleted file mode 100644
index 01f01bd..0000000
--- a/shared_counter.kpl
+++ /dev/null
@@ -1,57 +0,0 @@
-
-// Notice how counter can only be modified as read as [c]
-
-counter : %shared 0
-
-inc_dec : ([I64.amount]
- header : "#BOLD#Thread: %#, #WHITE#Counter:# " `format `thread_id
- body : ^ counter {[c]
- c +: amount
- ? {
- amount = 1 { "#GREEN#%#" `format c }
- amount = -1 { "#RED#%#" `format c }
- { "#UNDERLINE#INVALID#" }
- }
- }
- `log ,(header; body; "\n")
-)
-
-inc : inc_dec `bind 1
-dec : inc_dec `bind -1
-
-Inc_Dec_fn `type dec
-
-actions : %const 1_000
-
-batch : %const 100
-
-runner : ([Inc_Dec_fn.fn]
- total : actions
- @ total {
- `log "#WHITE#Batch: #CYAN#% #MAGENTA#%#\n" `format (fn; total)
- v : Array[`async_type fn] $ ()
- @ 1 .. batch { v `push `async fn }
- @ v {[x] `await x }
- total -: batch
- }
-)
-
-i : runner `async inc
-d : runner `async dec
-
-`log "#BOLD#YELLOW#SLEEPING THREAD %#\n" `format `thread_id
-
-`use "time" [Seconds]
-`use "sys" [sleep]
-
-sleep `sync Seconds $ 1
-
-`await (d; i)
-
-`log ^ counter {[c]
- ? !c {
- `format "#BOLD#GREEN#VALID#\n"
- } {
- `format "#BOLD#RED#INVALID#\n"
- }
-}