Skip to content

better support for multithreaded programs #64

@BurntSushi

Description

@BurntSushi

@Stebalien First off, thank you for maintaining this wonderful library. :-)

I came across a particular issue with the current API. Specifically, TerminfoTerminal::new_with_terminfo takes ownership over a TermInfo. Even though TermInfo is never mutated by a TerminfoTerminal, a TermInfo cannot be reused across multiple TerminfoTerminal values. In particular, the only way to amortize the cost of building a TermInfo is to clone it, but even this can be costly.

I'm not sure what the right API is, but I will note that using Arc solves my specific problem (which permits very cheap multithreaded read-only access).

There are potentially many other solutions, all with their own downsides:

  1. Require Arc<TermInfo> instead of TermInfo, but this feels a little strange to me.
  2. Require <T: AsRef<TermInfo>>. This means TermInfoTerminal will need to grow a type parameter.
  3. Define a new trait with the existing methods on TermInfo and require that. This also requires an additional type parameter.
  4. Make TermInfo an opaque struct and use an Arc internally, which will make cloning trivially cheap.

Other ideas? Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions