[PATCH 4/6] Cygwin: signal: Optimize the priority of the sig thread
Takashi Yano
takashi.yano@nifty.ne.jp
Mon Nov 25 13:15:43 GMT 2024
On Mon, 25 Nov 2024 21:16:20 +0900
Takashi Yano wrote:
> Previously, sig thread ran in THREAD_PRIORITY_HIGHEST priority.
> This caused critical delay in signal handling in the main thread
> if the too many signales are received rapidly and CPU is very busy.
> I this case, most of CPU time is allocated to sig thread, so the
> main thread cannot have a chance to handle signals. With this patch,
> the sig thread priority is set to the same priority with main thread
> to avoid such situation. Furthermore, if the signal is alarted to
> the main thread, but main thread does not handle it yet, in order to
> increase the chance to handle it in the main thread, reduce the sig
> thread priority is to THREAD_PRIORITY_LOWEST temporarily.
>
> Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256744.html
> Fixes: 53ad6f1394aa ("(cygthread::cygthread): Use three only arguments for detached threads, and start the thread via QueueUserAPC/async_create.")
> Reported-by: Christian Franke <Christian.Franke@t-online.de>
> Reviewed-by:
> Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
> ---
> winsup/cygwin/sigproc.cc | 8 ++++++++
> 1 file changed, 8 insertions(+)
>
> diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
> index 541f90cb7..75a5142fd 100644
> --- a/winsup/cygwin/sigproc.cc
> +++ b/winsup/cygwin/sigproc.cc
> @@ -1327,6 +1327,10 @@ wait_sig (VOID *)
> {
> DWORD nb;
> sigpacket pack = {};
> + /* Follow to the main thread priority */
> + int prio = GetThreadPriority (OpenThread (THREAD_QUERY_INFORMATION,
> + FALSE, _main_tls->thread_id));
> + SetThreadPriority (GetCurrentThread (), prio);
Oops! I forgot to close thread handle. I will submit v2 patch.
--
Takashi Yano <takashi.yano@nifty.ne.jp>
More information about the Cygwin-patches
mailing list