Skip to content

ASingleInstance#

Low-level cross-process single instance lock with activation forwarding.

Header:#include <AUI/Platform/ASingleInstance.h>
CMake:aui_link(my_target PUBLIC aui::core)

Detailed Description#

Most users would prefer AApplication::requestSingleInstanceLock.

Platform Implementation
Windows Named mutex Local\aui.<key>.<session> + named pipe
Linux GApplication (session D-Bus), if available
Unix flock on $XDG_RUNTIME_DIR/aui-<key>-<uid>.lock + unix domain socket (fallback)
Other Always primary

The lock is released automatically by the OS if the process dies, so a crashed primary instance never blocks new instances.

Public Types#


Impl#

struct ASingleInstance::Impl

Empty structure.

Public fields and Signals#


Callback#

using Callback

Activation callback. Called from a background thread.

Public Methods#

acquire#


static _unique<ASingleInstance> ASingleInstance::acquire(const AString& key, Callback onActivation)

Tries to become the primary instance for the given key.

Arguments
key
unique key of the application (i.e., app id).
onActivation
called (from a background thread) when another instance forwards its activation.
Returns
lock object if the current process is the primary instance. nullptr if another instance is running; in this case, activation of the current process has already been forwarded (synchronously) to the primary instance.