Single-threaded Io per component

My process has several long-running components.

Each component uses the Io interface only for synchronization and timeouts.

For this kind of functionality, each component creates its own Io using .init_single_threaded.

I think the “cost” of each single-threaded Io is negligible, at least in terms of memory consumption.
I also hope it results in fewer locks and less contention.

What is your opinion?

Why not use a single Threaded instance.

it won’t spawn threads unless you io.async or io.concurrent, and you can set limits on those when creating the instance.

did you mean - one shared Threaded for all components
or Threaded per-component with specific init options?

1 across all components

Component

  • uses sync. primitives
  • does not uses Io for i/o
  • self-contained

Reasons not to use own single-threaded Threaded Io - if such usage is prohibited or has performance implications

I don’t think that it has problem with performance

Use std.Io.Threaded.global_single_threaded.io() then.

1 Like

looks as happy path for all pre 0.16 sync. primitives

it worth to publish it as pattern/idiom