Shared_Memory_Channel module

reader_create_channel

procedureSource

Creates the channel called name with a region of bytes bytes and returns it as (success, channel). The caller becomes its reader and owns the name: nobody can connect until it exists, and the name goes away with reader_release_channel.

It fails if the name is taken (only one reader per name), the size is too small, or the system refuses; nothing is left behind then. Uses context.allocator for a small record that reader_release_channel frees.

Example
name := tprint("jai-doc-%", to_nanoseconds(current_time_monotonic()));

ok, reader := reader_create_channel(name, 1024);
assert(ok);
assert(reader.header.data_size_in_bytes == 768);

taken, again := reader_create_channel(name, 1024);
assert(!taken); // the name belongs to the first reader

assert(reader_release_channel(*reader));

Doesn't run in the browser (skipped on wasm).

reader_create_channel :: (
    name: string,
    bytes: s64
) -> (success: bool, channel: Read_Channel)

Parameters

name: string
bytes: s64

Returns

success: bool
channel: Read_Channel

See also