kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

141_threadlocal_mutate.toy (459B)


      1 // Thread-local storage: define a mutable _Thread_local, mutate it across calls,
      2 // and read it back. Single-threaded, so the interpreter resolves the TLV the
      3 // same storage the JIT does; both must agree.
      4 var @[.threadlocal] counter: i64 = 40;
      5 
      6 fn bump(): i64 {
      7   counter = counter + 1;
      8   return counter;
      9 }
     10 
     11 fn __user_main(): i64 {
     12   bump();          // 41
     13   bump();          // 42
     14   return bump();   // 43
     15 }
     16 
     17 fn main(): i32 { return __user_main() as i32; }