-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.
Milestone
Description
Some apps assume they only ever have one instance of themselves running on a given system.
It might make sense to provide this functionality under the std.process namespace if the interface can be cleanly mapped to platform-specific equivalents.
Windows provides CreateMutex for a global lock that can be checked against, proof of concept:
const std = @import("std");
const win = std.os.windows;
extern "kernel32" fn CreateMutexA(?*const win.SECURITY_ATTRIBUTES, win.BOOL, win.LPCSTR) callconv(win.WINAPI) ?win.HANDLE;
extern "user32" fn MessageBoxA(?win.HANDLE, ?win.LPCSTR, ?win.LPCSTR, win.UINT) callconv(win.WINAPI) i32;
fn win32_singleton(name: win.LPCSTR) error{ Unexpected, AlreadyExists }!win.HANDLE {
const m = CreateMutexA(null, 1, name);
const e = win.kernel32.GetLastError();
if (m) |h| {
if (e == .SUCCESS) return h;
if (e == .ALREADY_EXISTS) {
win.CloseHandle(h);
return error.AlreadyExists;
}
}
return win.unexpectedError(e);
}
pub fn main() !void {
_ = try win32_singleton("Hello World Program");
_ = MessageBoxA(null, "world", "hello", 0);
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.This issue suggests modifications. If it also has the "accepted" label then it is planned.standard libraryThis issue involves writing Zig code for the standard library.This issue involves writing Zig code for the standard library.