public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Gong, Sishuai" <sishuai@purdue.edu>
To: Jonathan Wakely <jwakely.gcc@gmail.com>
Cc: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: Re: Confirm the semantic of GCC extension "Conditionals with Omitted Operands"
Date: Thu, 23 Jul 2020 20:03:24 +0000	[thread overview]
Message-ID: <B24C84A4-DCA3-4939-92CB-24CE6B1CD011@purdue.edu> (raw)
In-Reply-To: <CAH6eHdT_WguJv8uS7ooxkRBuEQ3d1g63jVqqpShNAJzvrEWy7w@mail.gmail.com>

Hello,

Thanks for the clarification! I apologize for missing your first replies. For some reason, they didn’t come to my mailbox until yours.

Thanks,
Sishuai

> On Jul 23, 2020, at 3:39 PM, Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
> 
> On Thu, 23 Jul 2020 at 20:24, Gong, Sishuai via Gcc-help
> <gcc-help@gcc.gnu.org> wrote:
>> 
>> Hi,
>> 
>> I’d like to follow-up on my previous email.
>> 
>> What exactly is the semantic of the GCC extension “Conditionals with Omitted Operands”? Does it guarantee that the read operations of the first operand are only made once (which is not what happens in our experiments)? If not, is there a way to guarantee that the reads of the first operand are only made once to avoid concurrency problems (e.g., a double read that sees different results because of a write made by a concurrent thread)?
> 
> Did you read the previous replies?
> 
> To make a variable safe for concurrent access by multiple t threads
> you need to use atomic operations, and there is no atomic version of
> the ?: operator.
> 
> So you will need to do something like:
> 
> unsigned int hello(int *const *a)
> {
>    int b;
>    __atomic_load(a, &, __ATOMIC_SEQ_CST);
>    unsigned int c = b;
>    return c & 0xFE ?: 0x123;
> }
> 
> In other words, if the GCC extension doesn't provide the guarantees
> you need, do something different.


      reply	other threads:[~2020-07-23 20:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-01 14:11 Gong, Sishuai
2020-07-23 19:22 ` Gong, Sishuai
2020-07-23 19:39   ` Jonathan Wakely
2020-07-23 20:03     ` Gong, Sishuai [this message]

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=B24C84A4-DCA3-4939-92CB-24CE6B1CD011@purdue.edu \
    --to=sishuai@purdue.edu \
    --cc=gcc-help@gcc.gnu.org \
    --cc=jwakely.gcc@gmail.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).