Skip to content

Commit 3dcc0e6

Browse files
author
Andrew Pardoe
committed
2 parents 745b148 + 5ced8d0 commit 3dcc0e6

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

CppCoreGuidelines.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10760,7 +10760,7 @@ the same memory. Concurrent programming is tricky for many reasons, most
1076010760
importantly that it is undefined behavior to read data in one thread after it
1076110761
was written by another thread, if there is no proper synchronization between
1076210762
those threads. Making existing single-threaded code execute concurrently can be
10763-
as trivial as adding `std::async` or `std::thread` strategically, or it can be
10763+
as trivial as adding `std::async` or `std::thread` strategically, or it can
1076410764
necessitate a full rewrite, depending on whether the original code was written
1076510765
in a thread-friendly way.
1076610766

@@ -10939,7 +10939,7 @@ Help the tools:
1093910939
##### Reason
1094010940

1094110941
If you don't share writable data, you can't have a data race.
10942-
The less sharing you do, the less chance you have to forget to synchanize access (and get data races).
10942+
The less sharing you do, the less chance you have to forget to synchronize access (and get data races).
1094310943
The less sharing you do, the less chance you have to wait on a lock (so performance can improve).
1094410944

1094510945
##### Example
@@ -10965,7 +10965,7 @@ The less sharing you do, the less chance you have to wait on a lock (so performa
1096510965
// ...
1096610966
}
1096710967

10968-
Without those `const`s, we would have to review every asynchroneously invoked function for potential data races on `surface_readings`.
10968+
Without those `const`s, we would have to review every asynchronously invoked function for potential data races on `surface_readings`.
1096910969

1097010970
##### Note
1097110971

@@ -10981,7 +10981,7 @@ No locking is needed: You can't have a data race on a constant.
1098110981

1098210982
##### Reason
1098310983

10984-
A `thread` is a implementation concept, a way of thinking about the machine.
10984+
A `thread` is an implementation concept, a way of thinking about the machine.
1098510985
A task is an application notion, something you'd like to do, preferably concurrently with other tasks.
1098610986
Application concepts are easier to reason about.
1098710987

@@ -11072,7 +11072,7 @@ Concurrency rule summary:
1107211072
* [CP.27: Use plain `std::thread` for `thread`s that detach based on a run-time condition (only)](#Rconc-thread)
1107311073
* [CP.28: Remember to join scoped `thread`s that are not `detach()`ed](#Rconc-join)
1107411074
* [CP.30: Do not pass pointers to local variables to non-`raii_thread's](#Rconc-pass)
11075-
* [CP.31: Pass small amounts of data between threads by value, reather by reference or pointer](#Rconc-data)
11075+
* [CP.31: Pass small amounts of data between threads by value, rather than by reference or pointer](#Rconc-data)
1107611076
* [CP.32: To share ownership beween unrelated `thread`s use `shared_ptr`](#Rconc-shared)
1107711077
* [CP.40: Minimize context switching](#Rconc-switch)
1107811078
* [CP.41: Minimize thread creation and destruction](#Rconc-create)
@@ -11215,7 +11215,7 @@ If, as it is likely, `f()` invokes operations on `*this`, we must make sure that
1121511215

1121611216
##### Reason
1121711217

11218-
To maintain pointer safety and avoid leaks, we need to consider what pointers a used by a `thread`.
11218+
To maintain pointer safety and avoid leaks, we need to consider what pointers are used by a `thread`.
1121911219
If a `thread` joins, we can safely pass pointers to objects in the scope of the `thread` and its enclosing scopes.
1122011220

1122111221
##### Example
@@ -11254,7 +11254,7 @@ After that, the usual lifetime and ownership (for local objects) enforcement app
1125411254

1125511255
##### Reason
1125611256

11257-
To maintain pointer safety and avoid leaks, we need to consider what pointers a used by a `thread`.
11257+
To maintain pointer safety and avoid leaks, we need to consider what pointers are used by a `thread`.
1125811258
If a `thread` is detached, we can safely pass pointers to static and free store objects (only).
1125911259

1126011260
##### Example
@@ -11414,7 +11414,7 @@ A `thread` that has not been `detach()`ed when it is destroyed terminates the pr
1141411414

1141511415
##### Reason
1141611416

11417-
In general, you cannot know whether a non-`raii_thread` will outlife your thread (so that those pointers will become invalid.
11417+
In general, you cannot know whether a non-`raii_thread` will outlive the scope of the variables, so that those pointers will become invalid.
1141811418

1141911419
##### Example, bad
1142011420

@@ -11426,7 +11426,7 @@ In general, you cannot know whether a non-`raii_thread` will outlife your thread
1142611426
t0.detach();
1142711427
}
1142811428

11429-
The detach` may not be so easy to spot.
11429+
The `detach` may not be so easy to spot.
1143011430
Use a `raii_thread` or don't pass the pointer.
1143111431

1143211432
##### Example, bad
@@ -11435,10 +11435,10 @@ Use a `raii_thread` or don't pass the pointer.
1143511435

1143611436
##### Enforcement
1143711437

11438-
Flage pointers to locals passed in the constructor of a plain `thread`.
11438+
Flag pointers to locals passed in the constructor of a plain `thread`.
1143911439

1144011440

11441-
### <a name="Rconc-switch"></a>CP.31: Pass small amounts of data between threads by value, reather by reference or pointer
11441+
### <a name="Rconc-switch"></a>CP.31: Pass small amounts of data between threads by value, rather by reference or pointer
1144211442

1144311443
##### Reason
1144411444

@@ -11447,7 +11447,7 @@ Copying naturally gives unique ownership (simplifies code) and eliminates the po
1144711447

1144811448
##### Note
1144911449

11450-
Defining "small amount" precisely and is impossible.
11450+
Defining "small amount" precisely is impossible.
1145111451

1145211452
##### Example
1145311453

@@ -11462,7 +11462,7 @@ Defining "small amount" precisely and is impossible.
1146211462

1146311463
The call of `modify1` involves copying two `string` values; the call of `modify2` does not.
1146411464
On the other hand, the implementation of `modify1` is exactly as we would have written in for single-threaded code,
11465-
wheread the implementation of `modify2` will need some form of locking to avoid data races.
11465+
whereas the implementation of `modify2` will need some form of locking to avoid data races.
1146611466
If the string is short (say 10 characters), the call of `modify1` can be surprisingly fast;
1146711467
essentially all the cost is in the `thread` switch. If the string is long (say 1,000,000 characters), copying it twice
1146811468
is probably not a good idea.
@@ -11479,7 +11479,7 @@ message passing or shared memory.
1147911479

1148011480
##### Reason
1148111481

11482-
If treads are unrelated (that is, not known to be in the same scope or one within the lifetime of the other)
11482+
If threads are unrelated (that is, not known to be in the same scope or one within the lifetime of the other)
1148311483
and they need to share free store memory that needs to be deleted, a `shared_ptr` (or equivalent) is the only
1148411484
safe way to ensure proper deletion.
1148511485

@@ -11489,7 +11489,7 @@ safe way to ensure proper deletion.
1148911489

1149011490
##### Note
1149111491

11492-
* A static object (e.g. a global) can be shard because it is not owned in the sense that some thread is responsible for it's deletion.
11492+
* A static object (e.g. a global) can be shared because it is not owned in the sense that some thread is responsible for it's deletion.
1149311493
* An object on free store that is never to be deleted can be shared.
1149411494
* An object owned by one thread can be safely shared with another as long as that second thread doesn't outlive the owner.
1149511495

@@ -11502,7 +11502,7 @@ safe way to ensure proper deletion.
1150211502

1150311503
##### Reason
1150411504

11505-
Context swtiches are expesive.
11505+
Context swtiches are expensive.
1150611506

1150711507
##### Example
1150811508

@@ -11561,7 +11561,7 @@ Instead, we could have a set of pre-created worker threads processing the messag
1156111561

1156211562
##### Note
1156311563

11564-
If you system has a good thread pool, use it.
11564+
If your system has a good thread pool, use it.
1156511565
If your system has a good message queue, use it.
1156611566

1156711567
##### Enforcement
@@ -11636,7 +11636,7 @@ it will immediately go back to sleep, waiting.
1163611636

1163711637
##### Enforcement
1163811638

11639-
Flag all `waits` without conditions.
11639+
Flag all `wait`s without conditions.
1164011640

1164111641

1164211642
### <a name="Rconc-time"></a>CP.43: Minimize time spent in a critical section

0 commit comments

Comments
 (0)