88 lines
4.0 KiB
HTML
88 lines
4.0 KiB
HTML
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>Interrupted System Calls - Debugging with GDB</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html">
|
||
|
<meta name="description" content="Debugging with GDB">
|
||
|
<meta name="generator" content="makeinfo 4.13">
|
||
|
<link title="Top" rel="start" href="index.html#Top">
|
||
|
<link rel="up" href="Thread-Stops.html#Thread-Stops" title="Thread Stops">
|
||
|
<link rel="prev" href="Thread_002dSpecific-Breakpoints.html#Thread_002dSpecific-Breakpoints" title="Thread-Specific Breakpoints">
|
||
|
<link rel="next" href="Observer-Mode.html#Observer-Mode" title="Observer Mode">
|
||
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
||
|
<!--
|
||
|
Copyright (C) 1988-2019 Free Software Foundation, Inc.
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document
|
||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||
|
any later version published by the Free Software Foundation; with the
|
||
|
Invariant Sections being ``Free Software'' and ``Free Software Needs
|
||
|
Free Documentation'', with the Front-Cover Texts being ``A GNU Manual,''
|
||
|
and with the Back-Cover Texts as in (a) below.
|
||
|
|
||
|
(a) The FSF's Back-Cover Text is: ``You are free to copy and modify
|
||
|
this GNU Manual. Buying copies from GNU Press supports the FSF in
|
||
|
developing GNU and promoting software freedom.''
|
||
|
-->
|
||
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
||
|
<style type="text/css"><!--
|
||
|
pre.display { font-family:inherit }
|
||
|
pre.format { font-family:inherit }
|
||
|
pre.smalldisplay { font-family:inherit; font-size:smaller }
|
||
|
pre.smallformat { font-family:inherit; font-size:smaller }
|
||
|
pre.smallexample { font-size:smaller }
|
||
|
pre.smalllisp { font-size:smaller }
|
||
|
span.sc { font-variant:small-caps }
|
||
|
span.roman { font-family:serif; font-weight:normal; }
|
||
|
span.sansserif { font-family:sans-serif; font-weight:normal; }
|
||
|
--></style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="node">
|
||
|
<a name="Interrupted-System-Calls"></a>
|
||
|
<p>
|
||
|
Next: <a rel="next" accesskey="n" href="Observer-Mode.html#Observer-Mode">Observer Mode</a>,
|
||
|
Previous: <a rel="previous" accesskey="p" href="Thread_002dSpecific-Breakpoints.html#Thread_002dSpecific-Breakpoints">Thread-Specific Breakpoints</a>,
|
||
|
Up: <a rel="up" accesskey="u" href="Thread-Stops.html#Thread-Stops">Thread Stops</a>
|
||
|
<hr>
|
||
|
</div>
|
||
|
|
||
|
<h4 class="subsection">5.5.5 Interrupted System Calls</h4>
|
||
|
|
||
|
<p><a name="index-thread-breakpoints-and-system-calls-431"></a><a name="index-system-calls-and-thread-breakpoints-432"></a><a name="index-premature-return-from-system-calls-433"></a>There is an unfortunate side effect when using <span class="sc">gdb</span> to debug
|
||
|
multi-threaded programs. 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 <span class="sc">gdb</span> uses to implement breakpoints and other events that
|
||
|
stop execution.
|
||
|
|
||
|
<p>To handle this problem, your program should check the return value of
|
||
|
each system call and react appropriately. This is good programming
|
||
|
style anyways.
|
||
|
|
||
|
<p>For example, do not write code like this:
|
||
|
|
||
|
<pre class="smallexample"> sleep (10);
|
||
|
</pre>
|
||
|
<p>The call to <code>sleep</code> will return early if a different thread stops
|
||
|
at a breakpoint or for some other reason.
|
||
|
|
||
|
<p>Instead, write this:
|
||
|
|
||
|
<pre class="smallexample"> int unslept = 10;
|
||
|
while (unslept > 0)
|
||
|
unslept = sleep (unslept);
|
||
|
</pre>
|
||
|
<p>A system call is allowed to return early, so the system is still
|
||
|
conforming to its specification. But <span class="sc">gdb</span> does cause your
|
||
|
multi-threaded program to behave differently than it would without
|
||
|
<span class="sc">gdb</span>.
|
||
|
|
||
|
<p>Also, <span class="sc">gdb</span> 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.
|
||
|
|
||
|
</body></html>
|
||
|
|