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