From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31545 invoked by alias); 26 Oct 2003 15:00:01 -0000 Mailing-List: contact gdb-patches-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sources.redhat.com Received: (qmail 31496 invoked from network); 26 Oct 2003 15:00:00 -0000 Received: from unknown (HELO concert.shout.net) (204.253.184.25) by sources.redhat.com with SMTP; 26 Oct 2003 15:00:00 -0000 Received: from duracef.shout.net (duracef.shout.net [204.253.184.12]) by concert.shout.net (8.12.10/8.12.10) with ESMTP id h9QExPIr008972; Sun, 26 Oct 2003 08:59:25 -0600 Received: from duracef.shout.net (localhost [127.0.0.1]) by duracef.shout.net (8.12.10/8.12.9) with ESMTP id h9QExPfa022981; Sun, 26 Oct 2003 08:59:25 -0600 Received: (from mec@localhost) by duracef.shout.net (8.12.10/8.12.9/Submit) id h9QExPlc022980; Sun, 26 Oct 2003 09:59:25 -0500 Date: Sun, 26 Oct 2003 15:00:00 -0000 From: Michael Elizabeth Chastain Message-Id: <200310261459.h9QExPlc022980@duracef.shout.net> To: gdb-patches@sources.redhat.com Subject: [rfa/doc/threads] thread breakpoints and system calls Cc: drow@mvista.com, eliz@gnu.org X-SW-Source: 2003-10/txt/msg00769.txt.bz2 How embarrassing, my first doco on this was all wrong. How about this? Tested with makeinfo for syntax. Looking for approval from a thread guy such as Daniel J for content, and Eli Z for syntax. Michael C 2003-10-26 Michael Chastain * 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 14:53:09 -0000 *************** allows you to examine the overall state *** 3761,3766 **** --- 3761,3804 ---- 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. + + 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 + + It is legal behavior for a system call to return early, so @value{GDBN} + does not cause your program to behave illegally. 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