This is the mail archive of the gdb@sourceware.org mailing list for the GDB 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: A question about target_wait TARGET_WNOHANG and linux_nat_wait_1


On Tuesday 06 October 2009 16:54:43, Hui Zhu wrote:
> But if the TARGET_WNOHANG let wait return with a block threads, it
> will return 0.
> But if lwpid is 0, the wait will keep running, the wait is blocked.

You've snipped the important bit:

> But I found in linux_nat_wait_1:
>   while (lp == NULL)
>     {
>       pid_t lwpid;
> 
>       lwpid = my_waitpid (pid, &status, options);
> 
>       if (lwpid > 0)
>         {
> ...
>       if (pid == -1)
>         {

...
	  /* And every time we have checked both:
	     In async mode, return to event loop;
	     In sync mode, suspend waiting for a SIGCHLD signal.  */
	  if (options & __WCLONE)
	    {
	      if (target_options & TARGET_WNOHANG)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
		{
		  /* No interesting event.  */
		  ourstatus->kind = TARGET_WAITKIND_IGNORE;

		  if (debug_linux_nat_async)
		    fprintf_unfiltered (gdb_stdlog, "LLW: exit (ignore)\n");

		  restore_child_signals_mask (&prev_mask);
		  return minus_one_ptid;
                  ^^^^^^^^^^^^^^^^^^^^^^
		}

	      sigsuspend (&suspend_mask);
	    }

...

> 
>       /* We shouldn't end up here unless we want to try again.  */
>       gdb_assert (lp == NULL);
>     }

We always iterate at least twice, even with TARGET_WNOHANG, to
wait for clone and non-clone LWPs.  See the comment about __WALL at the
top of the file.  There's a description of async mode handling
nearby too.

> So the TARGET_WNOHANG is useless.

Not at all.

-- 
Pedro Alves


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