[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Why is "volatile" used in bash source code?
From: |
Eric Blake |
Subject: |
Re: [Help-bash] Why is "volatile" used in bash source code? |
Date: |
Wed, 6 Feb 2019 12:10:36 -0600 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 |
On 2/6/19 12:00 PM, Peng Yu wrote:
> Hi,
>
> I don't understand why "volatile" is used in bash source code. Could
> anybody help me understand why they are used? Thanks.
Which line of code in particular? Ask a vague question, and you'll get a
vague answer, which is:
One of the common uses for volatile is for performing correct
interactions between signal handlers and a main event loop - the
volatile keyword is essential to telling the compiler that a particular
variable might change externally (namely, in the course of a signal
handler that executes between when the variable was set earlier in a
function and then read later in the function), and therefore the
compiler must access memory every time rather than caching the
variable's last value in a register and missing out on the external change.
Now, if you ask about a PARTICULAR file/function/line of code that uses
volatile, I can give you more details why that particular use requires
the keyword.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3226
Virtualization: qemu.org | libvirt.org
signature.asc
Description: OpenPGP digital signature