Skip to content

Commit 9180af5

Browse files
committed
Update 07-Considering_Threadability.md
1 parent 7a29259 commit 9180af5

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

07-Considering_Threadability.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,20 @@
22

33
## Avoid Global Data
44

5-
This includes statics and singletons.
6-
75
Global data leads to unintended side effects between functions and can make code difficult or impossible to parallelize. Even if the code is not intended today for parallelization, there is no reason to make it impossible for the future.
86

7+
### Statics
8+
9+
Besides being global data, statics are not always constructed and deconstructed as you would expect. This is particularly true in cross-platform environments. See for example, [this g++ bug](9https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66830) regarding the order of destruction of shared static data loaded from dynamic modules.
10+
11+
### Shared Pointers
12+
13+
`std::shared_ptr` is "as good as a global" (http://stackoverflow.com/a/18803611/29975) because it allows multiple pieces of code to interact with the same data.
14+
15+
### Singletons
16+
17+
A singleton is often implemented with a static and/or `shared_ptr`
18+
919
## Avoid Heap Operations
1020

1121
Much slower in threaded environments. In many or maybe even most cases, copying data is faster. Plus with move operations and such and things.

0 commit comments

Comments
 (0)