| 1 | const std = @import("std"); |
| 2 | const assert = std.debug.assert; |
| 3 | |
| 4 | threadlocal var x: i32 = 1234; |
| 5 | |
| 6 | test "thread local storage" { |
| 7 | const thread1 = try std.Thread.spawn(.{}, testTls, .{}); |
| 8 | const thread2 = try std.Thread.spawn(.{}, testTls, .{}); |
| 9 | testTls(); |
| 10 | thread1.join(); |
| 11 | thread2.join(); |
| 12 | } |
| 13 | |
| 14 | fn testTls() void { |
| 15 | assert(x == 1234); |
| 16 | x += 1; |
| 17 | assert(x == 1235); |
| 18 | } |
| 19 | |
| 20 | // test |