142_threadlocal_multi.toy (559B)
1 // Multiple thread-locals: two independent _Thread_local vars, mutated together 2 // across calls, must keep separate storage and initializers. Single-threaded, 3 // so JIT (R) and interpreter (I) must agree on the same in-image storage. 4 var @[.threadlocal] a: i64 = 100; 5 var @[.threadlocal] b: i64 = 7; 6 7 fn step(): i64 { 8 a = a + 10; 9 b = b - 1; 10 return a + b; 11 } 12 13 fn __user_main(): i64 { 14 step(); // a=110 b=6 -> 116 15 step(); // a=120 b=5 -> 125 16 return step(); // a=130 b=4 -> 134 17 } 18 19 fn main(): i32 { return __user_main() as i32; }