Re: [PATCH 1/3] Cygwin: console: Ensure the master thread runs only when it is supposed to

Takashi Yano <[email protected]> Wed, 24 Jun 2026 21:12:49 +0900
Newsgroups gmane.os.cygwin.patches
Message-ID <[email protected]>
Thanks Mark,

On Wed, 24 Jun 2026 01:02:32 -0700
Mark Geisert wrote:
> Hi Takashi,
> 
> On 6/10/2026 9:35 AM, Takashi Yano wrote:
> > Currently, disabling cons_master_thread is done by just setting the
> > flag disable_master_thread. In fact, actual suspension of master
> > thread is delayed a bit. Therefore, non-cygwin program where the
> > master thread should be disabled may run even though the master
> > thread is running in a short time. This patch ensure that the master
> > thread is suspended when non-cygwin app is running. In addition,
> > while master thread is running, console mode should not be changed.
> > Therefore, the order of set_input_mode() call and disabling/enabling
> > master thread is swapped.
> > 
> > Fixes: d2b14c303c04 ("Cygwin: console: Redesign handling of special keys.")
> > Signed-off-by: Takashi Yano <[email protected]>
> > Reviewed-by:
> > ---
> >   winsup/cygwin/fhandler/console.cc | 15 +++++++++------
> >   1 file changed, 9 insertions(+), 6 deletions(-)
> > 
> > diff --git a/winsup/cygwin/fhandler/console.cc b/winsup/cygwin/fhandler/console.cc
> > index 45eff6efe..a5e6cd89d 100644
> > --- a/winsup/cygwin/fhandler/console.cc
> > +++ b/winsup/cygwin/fhandler/console.cc
> > @@ -439,6 +439,7 @@ fhandler_console::cons_master_thread (handle_set_t *p, tty *ttyp)
> >   
> >         if (con.disable_master_thread)
> >   	{
> > +	  con.master_thread_suspended = true;
> >   	  cygwait (40);
> >   	  continue;
> >   	}
> [...]
> 
> The only question I have for this patch is whether you need to set
>      con.master_thread_suspended = false
> right after the cygwait(40) call.  Can't tell if that's an omission or 
> it's intentional to 'continue' into the main body of the function with 
> that flag still true.

It's intentional. While disable_master_thread is true, master_thread is
suspended. master_thread checks disable_master_thread every 40msec, and
if disable_master_thread becomes false, set master_thread_suspended
false and starts working again.

> Other than that, LGTM.  OK to push.

-- 
Takashi Yano <[email protected]>