mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
21 lines
393 B
Zig
21 lines
393 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.join();
|
|
thread2.join();
|
|
}
|
|
|
|
fn testTls() void {
|
|
assert(x == 1234);
|
|
x += 1;
|
|
assert(x == 1235);
|
|
}
|
|
|
|
// test
|