Skip to content

Instantly share code, notes, and snippets.

@50n1cd347h9
Created July 30, 2024 07:00
Show Gist options
  • Save 50n1cd347h9/aa46c428381605f9d8413e70b3e4f2df to your computer and use it in GitHub Desktop.
Save 50n1cd347h9/aa46c428381605f9d8413e70b3e4f2df to your computer and use it in GitHub Desktop.
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