IMPORTANT: To view this page as Markdown, append `.md` to the URL (e.g. /max/get-started.md). For the complete documentation index, see llms.txt.
Skip to main content
For the complete documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /max/get-started.md).

Mojo struct

LamportGeneration

struct LamportGeneration

Owns the three-buffer generation rotation for a Lamport exchange.

The classic Lamport hazard is a fast rank racing into call N+1 and overwriting a slot a slow rank has not yet read for call N. Three rotating buffer generations defend against it: each call writes-and-reads one generation while clearing the generation that will be reused two calls later, leaving exactly one generation of skew slack.

Given a monotonically-increasing call counter flag:

  • data_index = flag % 3 is the generation written and read this call;
  • clear_index = (flag + 2) % 3 is the generation cleared back to the sentinel this call (it will next be written two calls from now).

data_index != clear_index always holds, which is the one-generation-of- slack invariant. This mirrors circular_add's pure-integer style in sync.mojo so the kernel body and any future broadcast consumer share identical semantics.

Implemented traits​

AnyType, ImplicitlyDeletable

comptime members​

NUM_GENERATIONS​

comptime NUM_GENERATIONS = 3

Number of rotating buffer generations: read-this-call + write-next-call + clear-for-the-call-after.

Methods​

data_index​

static def data_index(flag: Int) -> Int

Returns the generation index written and read on this call.

Args:

  • ​flag (Int): The monotonically-increasing call counter.

Returns:

Int: flag % NUM_GENERATIONS.

clear_index​

static def clear_index(flag: Int) -> Int

Returns the generation index cleared to the sentinel on this call.

This is the generation that will next be written two calls from now; clearing it now overlaps with the current exchange.

Args:

  • ​flag (Int): The monotonically-increasing call counter.

Returns:

Int: (flag + NUM_GENERATIONS - 1) % NUM_GENERATIONS, i.e. (flag + 2) % 3 for the default of three generations.

Was this page helpful?