Created
July 30, 2024 07:00
-
-
Save 50n1cd347h9/aa46c428381605f9d8413e70b3e4f2df to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const debugPrint = std.debug.print; | |
const Thread = std.Thread; | |
const Mutex = Thread.Mutex; | |
fn hoge(m: *Mutex, val: *u32) void { | |
const ret: u32 = val.* * 2; | |
{ | |
m.lock(); | |
defer m.unlock(); | |
debugPrint("ret = 0x{x}\n", .{ret}); | |
val.* = ret; | |
} | |
return; | |
} | |
pub fn main() !void { | |
var m: Mutex = undefined; | |
var ahi: u32 = 0xdead; | |
const thread = try Thread.spawn(.{}, hoge, .{ &m, &ahi }); | |
thread.join(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment