isocpp / isocpp/CppCoreGuidelines

CP.25: gsl::joining_thread missing implementation in Guidelines support library

Open
#2,036 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
CSS
Stars
45.3k
Forks
5.6k
PR merge metrics
No merged PRs in 30d

Description

Problem

CP.25 says "Prefer gsl::joining_thread over std::thread". However there is no implementation of gsl::joining_thread in Microsoft GSL. Hence the rule CP.25 is incorrect.

Workaround

For projects using C++20, CP.25 could be reworded to "Prefer std::jthread to std::thread".
For projects using C++11 & higher, there should be a workaround to handle this broken rule.

The textbook "C++ Concurrency in action - Practical Multithreading" by Anthony Williams, Chapter 2: "Managing threads", Section 2.3: "Transferring ownership of a thread" under Listing 2.6: "scoped_thread and example usage" mentions an example implementation of scoped_thread class which could be a useful workaround to handle this scenario for projects lesser than C++20 version.

Rainer Grimm's blog also mentions about this workaround.

Action item

It would be nice to incorporate the above workarounds or a better solution to address the incorrect CP.25 rule. If this workarounds are okay for reviewers, I can support in creating a pull request to edit the rule. Let me know your valuable thoughts on this.

Thanks,
Honey

Honey Sukesan

Contributor guide

Open the contributing guide

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 the CP.25 rule and its linked C++ Core Guidelines text; compare its recommendation with std::jthread for C++20 and the pre-C++20 workaround described in the issue. Done means the rule no longer recommends an unavailable gsl::joining_thread and clearly addresses supported language versions.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.