| ... | ... | @@ -7,7 +7,6 @@ const expectError = testing.expectError; |
| 7 | 7 | const fs = std.fs; |
| 8 | 8 | const mem = std.mem; |
| 9 | 9 | const elf = std.elf; |
| 10 | | const Thread = std.Thread; |
| 11 | 10 | const linux = std.os.linux; |
| 12 | 11 | |
| 13 | 12 | const a = std.testing.allocator; |
| ... | ... | @@ -446,70 +445,6 @@ test "readlinkat" { |
| 446 | 445 | try expect(mem.eql(u8, "file.txt", read_link)); |
| 447 | 446 | } |
| 448 | 447 | |
| 449 | | fn testThreadIdFn(thread_id: *Thread.Id) void { |
| 450 | | thread_id.* = Thread.getCurrentId(); |
| 451 | | } |
| 452 | | |
| 453 | | test "Thread.getCurrentId" { |
| 454 | | if (builtin.single_threaded) return error.SkipZigTest; |
| 455 | | |
| 456 | | var thread_current_id: Thread.Id = undefined; |
| 457 | | const thread = try Thread.spawn(.{}, testThreadIdFn, .{&thread_current_id}); |
| 458 | | thread.join(); |
| 459 | | try expect(Thread.getCurrentId() != thread_current_id); |
| 460 | | } |
| 461 | | |
| 462 | | test "spawn threads" { |
| 463 | | if (builtin.single_threaded) return error.SkipZigTest; |
| 464 | | |
| 465 | | var shared_ctx: i32 = 1; |
| 466 | | |
| 467 | | const thread1 = try Thread.spawn(.{}, start1, .{}); |
| 468 | | const thread2 = try Thread.spawn(.{}, start2, .{&shared_ctx}); |
| 469 | | const thread3 = try Thread.spawn(.{}, start2, .{&shared_ctx}); |
| 470 | | const thread4 = try Thread.spawn(.{}, start2, .{&shared_ctx}); |
| 471 | | |
| 472 | | thread1.join(); |
| 473 | | thread2.join(); |
| 474 | | thread3.join(); |
| 475 | | thread4.join(); |
| 476 | | |
| 477 | | try expect(shared_ctx == 4); |
| 478 | | } |
| 479 | | |
| 480 | | fn start1() u8 { |
| 481 | | return 0; |
| 482 | | } |
| 483 | | |
| 484 | | fn start2(ctx: *i32) u8 { |
| 485 | | _ = @atomicRmw(i32, ctx, AtomicRmwOp.Add, 1, AtomicOrder.seq_cst); |
| 486 | | return 0; |
| 487 | | } |
| 488 | | |
| 489 | | test "cpu count" { |
| 490 | | if (native_os == .wasi) return error.SkipZigTest; |
| 491 | | |
| 492 | | const cpu_count = try Thread.getCpuCount(); |
| 493 | | try expect(cpu_count >= 1); |
| 494 | | } |
| 495 | | |
| 496 | | test "thread local storage" { |
| 497 | | if (builtin.single_threaded) return error.SkipZigTest; |
| 498 | | |
| 499 | | const thread1 = try Thread.spawn(.{}, testTls, .{}); |
| 500 | | const thread2 = try Thread.spawn(.{}, testTls, .{}); |
| 501 | | try testTls(); |
| 502 | | thread1.join(); |
| 503 | | thread2.join(); |
| 504 | | } |
| 505 | | |
| 506 | | threadlocal var x: i32 = 1234; |
| 507 | | fn testTls() !void { |
| 508 | | if (x != 1234) return error.TlsBadStartValue; |
| 509 | | x += 1; |
| 510 | | if (x != 1235) return error.TlsBadEndValue; |
| 511 | | } |
| 512 | | |
| 513 | 448 | test "getrandom" { |
| 514 | 449 | var buf_a: [50]u8 = undefined; |
| 515 | 450 | var buf_b: [50]u8 = undefined; |