Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Michael Elizabeth Chastain <mec@shout.net>
To: drow@mvista.com, gdb-patches@sources.redhat.com
Cc: eliz@gnu.org
Subject: Re: [rfa/doc/threads] thread breakpoints and system calls
Date: Sun, 26 Oct 2003 21:35:00 -0000	[thread overview]
Message-ID: <200310262134.h9QLY3IM027424@duracef.shout.net> (raw)

Okay, how about this?

This version eschews the words 'legal' and 'illegal'.  It also adds a
sentence about the root cause, which is the interaction between
multiple threads and the signals used to implement breakpoints and
other events that stop execution.

Tested with makeinfo for syntax.

Michael C

2003-10-26  Michael Chastain  <mec@shout.net>

	* gdb.texinfo (Thread Stops): Document the issue with
	premature return from system calls in multi-threaded programs.

Index: gdb.texinfo
===================================================================
RCS file: /cvs/src/src/gdb/doc/gdb.texinfo,v
retrieving revision 1.183
diff -c -3 -p -r1.183 gdb.texinfo
*** gdb.texinfo	23 Oct 2003 00:11:59 -0000	1.183
--- gdb.texinfo	26 Oct 2003 21:28:00 -0000
*************** allows you to examine the overall state 
*** 3761,3766 ****
--- 3761,3807 ----
  switching between threads, without worrying that things may change
  underfoot.
  
+ @cindex thread breakpoints and system calls
+ @cindex system calls and thread breakpoints
+ @cindex premature return from system calls
+ There is an unfortunate side effect.  If one thread stops for a
+ breakpoint, or for some other reason, and another thread is blocked in a
+ system call, then the system call may return prematurely.  This is a
+ consequence of the interaction between multiple threads and the signals
+ that @value{GDBN} uses to implement breakpoints and other events that
+ stop execution.
+ 
+ To handle this problem, your program should check the return value of
+ each system call and react appropriately.  This is good programming
+ style anyways.
+ 
+ For example, do not write code like this:
+ 
+ @smallexample
+   sleep (10);
+ @end smallexample
+ 
+ The call to @code{sleep} will return early if a different thread stops
+ at a breakpoint or for some other reason.
+ 
+ Instead, write this:
+ 
+ @smallexample
+   int unslept = 10;
+   while (unslept > 0)
+     unslept = sleep (unslept);
+ @end smallexample
+ 
+ A system call is allowed to return early, so the system is still
+ conforming to its specification.  But @value{GDBN} does cause your
+ multi-threaded program to behave differently than it would without
+ @value{GDBN}.
+ 
+ Also, @value{GDBN} uses internal breakpoints in the thread library to
+ monitor certain events such as thread creation and thread destruction.
+ When such an event happens, a system call in another thread may return
+ prematurely, even though your program does not appear to stop.
+ 
  @cindex continuing threads
  @cindex threads, continuing
  Conversely, whenever you restart the program, @emph{all} threads start


             reply	other threads:[~2003-10-26 21:35 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-26 21:35 Michael Elizabeth Chastain [this message]
2003-10-27  6:01 ` Eli Zaretskii
2003-10-27  6:04   ` Daniel Jacobowitz
  -- strict thread matches above, loose matches on Subject: below --
2003-10-27 14:01 Michael Elizabeth Chastain
2003-10-26 15:00 Michael Elizabeth Chastain
2003-10-26 17:35 ` Eli Zaretskii
2003-10-26 17:39   ` Daniel Jacobowitz
2003-10-27 16:12   ` Andrew Cagney
2003-10-27 20:04     ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200310262134.h9QLY3IM027424@duracef.shout.net \
    --to=mec@shout.net \
    --cc=drow@mvista.com \
    --cc=eliz@gnu.org \
    --cc=gdb-patches@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox