> On Mon, 20 Nov 2000, Martin Husemann wrote:
>
> : What now happens on sparc64 is: the sigchld function modifies the struct
> : pointed to by "j" in this loop, returns, thus waking up the sigsuspend a
> : few lines below, continues to the "while" check and still has the old value
> : of j->state in a register, checks against that and continues the loop one
> : more time - thus blocking in "sigsuspend" again.
>
> Which means that this is a bug in gcc, not a bug in the ksh code.
>
> I'll see what I can find out about the codegen, and may submit a gcc PR.
>
It doesn't look particularly like a gcc bug to me. If j->state is being
updated from within a signal handler, then it must be declared volatile in
the original declaration *and in all references to it*. Adding casts is
not good enough.
But in jobs.c we see:
struct job {
Job *next; /* next job in list */
int job; /* job number: %n */
int flags; /* see JF_* */
int state; /* job state */
int status; /* exit status of last process */
...
So the declaration here, for starters, is invalid.
The same also applies to any other object that is being touched from
within the signal handler.
Richard.