cplusplus / cplusplus/draft

[atomics.types.operations] Possibly unintended example

Open
#8,715 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P3-Other
Dominant language
TeX
Stars
221
Forks
813
Avg merge
16h 4m
Merged PRs (30d)
36

Description

The example in [atomics.types.operations] Note 8 currently reads:

union pony {
  double celestia = 0.;
  short luna;       // padded
};
atomic<pony> princesses = {};

bool party(pony desired) {
  pony expected;
  return princesses.compare_exchange_strong(expected, desired);
}

In common implementations, pony have the same size as double and a default- or value-initialized pony doesn't have any bit with indeterminate value. So it's questionable to me whether this example serves its purpose. Would it make more sense to initialize the short member instead?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Note 8 of [atomics.types.operations] and read the surrounding atomic operations wording. Check whether the example demonstrates the intended padding or indeterminate-value behavior, then revise the example if needed; the issue is resolved when the note clearly serves its intended purpose.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.