@@ -10253,7 +10253,7 @@ the same memory. Concurrent programming is tricky for many reasons, most
10253
10253
importantly that it is undefined behavior to read data in one thread after it
10254
10254
was written by another thread, if there is no proper synchronization between
10255
10255
those threads. Making existing single-threaded code execute concurrently can be
10256
- as trivial as adding `std::async` or `std::thread` strategically, or it can be
10256
+ as trivial as adding `std::async` or `std::thread` strategically, or it can
10257
10257
necessitate a full rewrite, depending on whether the original code was written
10258
10258
in a thread-friendly way.
10259
10259
@@ -10432,7 +10432,7 @@ Help the tools:
10432
10432
##### Reason
10433
10433
10434
10434
If you don't share writable data, you can't have a data race.
10435
- The less sharing you do, the less chance you have to forget to synchanize access (and get data races).
10435
+ The less sharing you do, the less chance you have to forget to synchronize access (and get data races).
10436
10436
The less sharing you do, the less chance you have to wait on a lock (so performance can improve).
10437
10437
10438
10438
##### Example
@@ -10458,7 +10458,7 @@ The less sharing you do, the less chance you have to wait on a lock (so performa
10458
10458
// ...
10459
10459
}
10460
10460
10461
- Without those `const`s, we would have to review every asynchroneously invoked function for potential data races on `surface_readings`.
10461
+ Without those `const`s, we would have to review every asynchronously invoked function for potential data races on `surface_readings`.
10462
10462
10463
10463
##### Note
10464
10464
@@ -10474,7 +10474,7 @@ No locking is needed: You can't have a data race on a constant.
10474
10474
10475
10475
##### Reason
10476
10476
10477
- A `thread` is a implementation concept, a way of thinking about the machine.
10477
+ A `thread` is an implementation concept, a way of thinking about the machine.
10478
10478
A task is an application notion, something you'd like to do, preferably concurrently with other tasks.
10479
10479
Application concepts are easier to reason about.
10480
10480
@@ -10565,7 +10565,7 @@ Concurrency rule summary:
10565
10565
* [CP.27: Use plain `std::thread` for `thread`s that detach based on a run-time condition (only)](#Rconc-thread)
10566
10566
* [CP.28: Remember to join scoped `thread`s that are not `detach()`ed](#Rconc-join)
10567
10567
* [CP.30: Do not pass pointers to local variables to non-`raii_thread's](#Rconc-pass)
10568
- * [CP.31: Pass small amounts of data between threads by value, reather by reference or pointer](#Rconc-data)
10568
+ * [CP.31: Pass small amounts of data between threads by value, rather than by reference or pointer](#Rconc-data)
10569
10569
* [CP.32: To share ownership beween unrelated `thread`s use `shared_ptr`](#Rconc-shared)
10570
10570
* [CP.40: Minimize context switching](#Rconc-switch)
10571
10571
* [CP.41: Minimize thread creation and destruction](#Rconc-create)
@@ -10708,7 +10708,7 @@ If, as it is likely, `f()` invokes operations on `*this`, we must make sure that
10708
10708
10709
10709
##### Reason
10710
10710
10711
- To maintain pointer safety and avoid leaks, we need to consider what pointers a used by a `thread`.
10711
+ To maintain pointer safety and avoid leaks, we need to consider what pointers are used by a `thread`.
10712
10712
If a `thread` joins, we can safely pass pointers to objects in the scope of the `thread` and its enclosing scopes.
10713
10713
10714
10714
##### Example
@@ -10747,7 +10747,7 @@ After that, the usual lifetime and ownership (for local objects) enforcement app
10747
10747
10748
10748
##### Reason
10749
10749
10750
- To maintain pointer safety and avoid leaks, we need to consider what pointers a used by a `thread`.
10750
+ To maintain pointer safety and avoid leaks, we need to consider what pointers are used by a `thread`.
10751
10751
If a `thread` is detached, we can safely pass pointers to static and free store objects (only).
10752
10752
10753
10753
##### Example
@@ -10907,7 +10907,7 @@ A `thread` that has not been `detach()`ed when it is destroyed terminates the pr
10907
10907
10908
10908
###### Reason
10909
10909
10910
- In general, you cannot know whether a non-`raii_thread` will outlife your thread ( so that those pointers will become invalid.
10910
+ In general, you cannot know whether a non-`raii_thread` will outlive the scope of the variables, so that those pointers will become invalid.
10911
10911
10912
10912
##### Example, bad
10913
10913
@@ -10919,7 +10919,7 @@ In general, you cannot know whether a non-`raii_thread` will outlife your thread
10919
10919
t0.detach();
10920
10920
}
10921
10921
10922
- The detach` may not be so easy to spot.
10922
+ The ` detach` may not be so easy to spot.
10923
10923
Use a `raii_thread` or don't pass the pointer.
10924
10924
10925
10925
##### Example, bad
@@ -10928,10 +10928,10 @@ Use a `raii_thread` or don't pass the pointer.
10928
10928
10929
10929
##### Enforcement
10930
10930
10931
- Flage pointers to locals passed in the constructor of a plain `thread`.
10931
+ Flag pointers to locals passed in the constructor of a plain `thread`.
10932
10932
10933
10933
10934
- ### <a name="Rconc-switch"></a>CP.31: Pass small amounts of data between threads by value, reather by reference or pointer
10934
+ ### <a name="Rconc-switch"></a>CP.31: Pass small amounts of data between threads by value, rather by reference or pointer
10935
10935
10936
10936
##### Reason
10937
10937
@@ -10940,7 +10940,7 @@ Copying naturally gives unique ownership (simplifies code) and eliminates the po
10940
10940
10941
10941
##### Note
10942
10942
10943
- Defining "small amount" precisely and is impossible.
10943
+ Defining "small amount" precisely is impossible.
10944
10944
10945
10945
##### Example
10946
10946
@@ -10955,7 +10955,7 @@ Defining "small amount" precisely and is impossible.
10955
10955
10956
10956
The call of `modify1` involves copying two `string` values; the call of `modify2` does not.
10957
10957
On the other hand, the implementation of `modify1` is exactly as we would have written in for single-threaded code,
10958
- wheread the implementation of `modify2` will need some form of locking to avoid data races.
10958
+ whereas the implementation of `modify2` will need some form of locking to avoid data races.
10959
10959
If the string is short (say 10 characters), the call of `modify1` can be surprisingly fast;
10960
10960
essentially all the cost is in the `thread` switch. If the string is long (say 1,000,000 characters), copying it twice
10961
10961
is probably not a good idea.
@@ -10972,7 +10972,7 @@ message passing or shared memory.
10972
10972
10973
10973
##### Reason
10974
10974
10975
- If treads are unrelated (that is, not known to be in the same scope or one within the lifetime of the other)
10975
+ If threads are unrelated (that is, not known to be in the same scope or one within the lifetime of the other)
10976
10976
and they need to share free store memory that needs to be deleted, a `shared_ptr` (or equivalent) is the only
10977
10977
safe way to ensure proper deletion.
10978
10978
@@ -10982,7 +10982,7 @@ safe way to ensure proper deletion.
10982
10982
10983
10983
##### Note
10984
10984
10985
- * 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.
10985
+ * 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.
10986
10986
* An object on free store that is never to be deleted can be shared.
10987
10987
* An object owned by one thread can be safely shared with another as long as that second thread doesn't outlive the owner.
10988
10988
@@ -10995,7 +10995,7 @@ safe way to ensure proper deletion.
10995
10995
10996
10996
##### Reason
10997
10997
10998
- Context swtiches are expesive .
10998
+ Context swtiches are expensive .
10999
10999
11000
11000
##### Example
11001
11001
@@ -11054,7 +11054,7 @@ Instead, we could have a set of pre-created worker threads processing the messag
11054
11054
11055
11055
###### Note
11056
11056
11057
- If you system has a good thread pool, use it.
11057
+ If your system has a good thread pool, use it.
11058
11058
If your system has a good message queue, use it.
11059
11059
11060
11060
##### Enforcement
@@ -11129,7 +11129,7 @@ it will immediately go back to sleep, waiting.
11129
11129
11130
11130
##### Enforcement
11131
11131
11132
- Flag all `waits` without conditions.
11132
+ Flag all `wait`s without conditions.
11133
11133
11134
11134
11135
11135
### <a name="Rconc-time"></a>CP.43: Minimize time spent in a critical section
0 commit comments