gtopt/scoped_stdout_silencer.hpp file

Thread-safe RAII redirect of fd 1 (stdout) to /dev/null.

Some solver libraries (MindOpt, Gurobi) print a banner to stdout while their environment is created, and the banner cannot be suppressed via the API. The plugins therefore point fd 1 at /dev/null around the environment creation.

Doing that with a bare dup / dup2 pair is not thread-safe: when two backends are constructed concurrently (SDDP clones, parallel tests) the second thread can save the already redirected descriptor and later "restore" /dev/null, leaving the whole process with stdout silenced for good (the doctest summary then silently disappears).

ScopedStdoutSilencer serialises the redirect behind a process-wide mutex and reference count: the first live instance saves the real stdout and redirects it, the last one to die restores it. The restore happens in the destructor, so every exit path (including exceptions) puts stdout back.

Namespaces

namespace gtopt

Classes

class gtopt::ScopedStdoutSilencer