LWN.net Logo

Advertisement

Our team patches and enhances the Linux kernel and promotes the adoption of Linux at Oracle. mark.wilkerson @oracle.com

Advertise here

Swap

Swap

Posted Apr 2, 2013 9:17 UTC (Tue) by tialaramex (subscriber, #21167)
In reply to: Swap by proski
Parent article: A look at C++14: Papers Part 2

I can imagine that there might be platforms on which (especially for larger or more sophisticated native C types like doubles) atomic swap is not practical.

So perhaps C could consider offering swap with no promises of atomicity, plus a set of reserved pre-processor variables which tell us whether atomicity is implemented for specific types. This would let you do

#if !defined(SWAP_UINT64_T_IS_ATOMIC)
#error This program requires an atomic swap for unsigned 64-bit integers but you don't have one. Too bad.
#endif

... or something more useful, but you get the idea.


(Log in to post comments)

Swap

Posted Apr 2, 2013 20:12 UTC (Tue) by scottwood (subscriber, #74349) [Link]

If non-atomic swap is a useful addition, why would you want to slow down swaps that don't need to be atomic by making it automatic, even if it's optional for the implementation? Atomic swap should be a specially requested operation (e.g. using compiler intrinsics), just like most other atomic operations.

Swap

Posted Apr 3, 2013 5:05 UTC (Wed) by Ben_P (subscriber, #74247) [Link]

Atomic swaps on doubles (and floats) are made more tricky by the fact very often NaN != NaN.

Swap

Posted Apr 5, 2013 23:18 UTC (Fri) by mathstuf (subscriber, #69389) [Link]

Can't you just treat them as integers of the same size for CAS?

Copyright © 2013, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds