You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

19 lines
387 B
Zig

const std = @import("std");
const assert = std.debug.assert;
threadlocal var x: i32 = 1234;
test "thread local storage" {
const thread1 = try std.Thread.spawn({}, testTls);
const thread2 = try std.Thread.spawn({}, testTls);
testTls({});
thread1.wait();
thread2.wait();
}
fn testTls(context: void) void {
assert(x == 1234);
x += 1;
assert(x == 1235);
}