This is the mail archive of the
gdb@sourceware.org
mailing list for the GDB project.
Re: A question about target_wait TARGET_WNOHANG and linux_nat_wait_1
- From: Pedro Alves <pedro at codesourcery dot com>
- To: gdb at sourceware dot org
- Cc: Hui Zhu <teawater at gmail dot com>
- Date: Tue, 6 Oct 2009 17:04:40 +0100
- Subject: Re: A question about target_wait TARGET_WNOHANG and linux_nat_wait_1
- References: <daef60380910060854t273f2e00q2f688da43e89b8a9@mail.gmail.com>
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