git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Safe to use stdatomic.h?

From
Jeff King <peff@peff.net>
Date
Mar 20, 2017, 20:27 UTC
Message-ID
<20170320202755.ospj7o6dfczti6wp@sigill.intra.peff.net>
In-Reply-To
<000801d2a1b7$1ec41620$5c4c4260$@gmail.com>
On Mon, Mar 20, 2017 at 04:18:20PM -0400, Ben Peart wrote:
Show 10 quoted lines
> My college Jeff is working on a patch series to further parallelize the
> loading of the index.  As part of that patch, it would be nice to use the
> atomic_fetch_add function as that would be more efficient than creating a
> mutex simply to protect a variable so that it can be incremented.  I haven't
> seen any use of atomics yet in Git, nor anything that includes
> <stdatomic.h>.
> 
> GCC has supported them since 4.9 and Clang has supported them by default
> since 3.3.  Are there any compilers currently in use by Git that don't
> support these C11 functions?

Yes, there definitely are older compilers in use. However, if you can abstract the operation you want to perform into its own function, it's perfectly fine to #ifdef it to use the atomics when available and fall back to a mutex otherwise.

-Peff
Previous: Ben PeartNext: brian m. carlson
Message 2 of 4 in “Safe to use stdatomic.h?”
  1. Ben PeartMar 20, 2017
  2. Jeff KingMar 20, 2017
  3. brian m. carlsonMar 20, 2017
  4. Eric WongMar 21, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.