On Dec 4 20:41, Takashi Yano wrote: > Currently, the signal queue is touched by the thread sig as well as > other threads that call sigaction_worker(). This potentially has > a possibility to destroy the signal queue chain. A possible worst > result may be a self-loop chain which causes infinite loop. With > this patch, lock()/unlock() are introduce to avoid such a situation.
I was hoping for a lockfree solution, but never mind that for now. > > diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc > index 7e02e61f7..cc3113b88 100644 > --- a/winsup/cygwin/sigproc.cc > +++ b/winsup/cygwin/sigproc.cc > @@ -106,12 +106,27 @@ class pending_signals > { > sigpacket sigs[_NSIG + 1]; > sigpacket start; > + volatile unsigned locked; > bool retry; > + void lock () > + { > + while (InterlockedExchange (&locked, 1)) > + { > +#ifdef __x86_64__ > + __asm__ ("pause"); > +#else > +#error unimplemented for this target > +#endif > + yield (); > + } > + } > + void unlock () { locked = 0; } > > public: > + pending_signals (): locked(0) {} > void add (sigpacket&); > bool pending () {retry = !!start.next; return retry;} > - void clear (int sig); > + void clear (int sig, bool need_lock); > void clear (_cygtls *tls); > friend void sig_dispatch_pending (bool); > friend void wait_sig (VOID *arg); Given this is used in C-code only, what about just using SRWLocks in Exclusive-only mode, rather than a spinlock? Thanks, Corinna