# `Lockstep.Global`
[🔗](https://github.com/b-erdem/lockstep/blob/v0.1.0/lib/lockstep/global.ex#L1)

Cluster-wide name registry, mirror of Erlang's `:global`.

## Phase C semantics (simplified)

  * Single shared name table maintained at the controller level
  * `register_name(name, pid)` succeeds globally if `name` is free,
    returns `:no` otherwise
  * `whereis_name(name)` returns the pid (or `:undefined`)
  * No two-phase commit, no name conflict resolution after partition
    heal -- if two partitioned sides could each register the same
    name independently, that case isn't modeled here
  * Cross-node `whereis_name` works during partition (same shared
    table)

Real `:global` does much more (sync protocol, conflict callbacks,
atomic register-or-fail across nodes). The simplified version
covers the most common usage: one process registers a name, others
look it up. If you need split-brain semantics, build them on top
of `Lockstep.Cluster.partition`.

## Implementation

Backed directly by a cluster-wide table inside the
`Lockstep.Controller` (no per-node namespacing, no auxiliary gen_server).
Names are auto-cleared when the registered pid dies.

## Rewriter integration

`Lockstep.Rewriter` rewrites `:global.{register_name,
unregister_name, whereis_name, sync, send, registered_names}` to
the corresponding `Lockstep.Global.*` calls.

# `register_name`

```elixir
@spec register_name(any(), pid()) :: :yes | :no
```

Register `pid` under cluster-wide `name`. Returns `:yes` on
success, `:no` if the name is already taken or `pid` already owns
another name.

# `registered_names`

```elixir
@spec registered_names() :: [any()]
```

Names currently registered globally.

# `send`

```elixir
@spec send(any(), any()) :: pid()
```

Send `msg` to the pid registered as `name`. Raises if no such name.
Mirrors `:global.send/2`.

# `sync`

```elixir
@spec sync() :: :ok
```

Synchronize the global name table -- a no-op in this simplified
model since the single controller-side table is always consistent.
Provided for source compatibility with real `:global`.

# `unregister_name`

```elixir
@spec unregister_name(any()) :: any()
```

Unregister `name`. Returns the freed name.

# `whereis_name`

```elixir
@spec whereis_name(any()) :: pid() | :undefined
```

Return the pid registered under `name`, or `:undefined`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
