This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2] Remove signal handling for nanosleep (bug 16364)


Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:

> +/* Fork and terminate the child in 0.25s while parent waits on a nanosleep
> +   for 0.5s.  */
> +static int
> +check_nanosleep_base (void)
> +{
> +  int ret = 0;
> +  pid_t f = fork ();
> +  if (f == 0)
> +    {
> +      // child
> +      struct timespec tv = { .tv_sec = 0, .tv_nsec = 250000000UL };
> +      nanosleep (&tv, &tv);
> +      _exit (EXIT_SUCCESS);
> +    }
> +  else if (f > 0)
> +    {
> +      // parent
> +      struct timespec tv = { .tv_sec = 0, .tv_nsec = 500000000UL };
> +      ret = nanosleep (&tv, &tv);
> +    }
> +  else if (f == -1)
> +    {
> +      puts ("error: fork failed");
> +      _exit (EXIT_FAILURE);
> +    }
> +  return ret;
> +}

You should wait for the child before returning.
How do you avoid the race between the parent and the child?

Andreas.

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]