[SERVER-47518] mitigate dtor-order fiasco with a utility for defining static duration immortal objects Created: 13/Apr/20 Updated: 29/Oct/23 Resolved: 07/May/20 |
|
| Status: | Closed |
| Project: | Core Server |
| Component/s: | Internal Code |
| Affects Version/s: | None |
| Fix Version/s: | 4.4.1, 4.7.0 |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Billy Donahue | Assignee: | Billy Donahue |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Backwards Compatibility: | Fully Compatible | ||||
| Backport Requested: |
v4.4
|
||||
| Sprint: | Service arch 2020-05-18 | ||||
| Participants: | |||||
| Description |
|
A template with an object-modeling API similar to std::optional, Init examples from the unit test:
x is convertible to an Indestructible&, and can sometimes be passed directly. Immortal forwards (via placement new) its constructor arguments to T(args...). This performs a placement new onto a std::aligned_buffer_t, so there is no allocation as there would be with the traditional approach, and there is no destructor call. Having a common idiom and place to hang documentation will be useful in cutting down on the very common misuses and bugs we have regarding init order and shutdown order. Importantly, it becomes a "greppable" and auditable best practice to identify and contain such objects, which are often suspects in startup and shutdown problems, or need to be called out in refactorings to reduce shared global state. |
| Comments |
| Comment by Githook User [ 23/Oct/20 ] |
|
Author: {'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}Message: |
| Comment by Githook User [ 18/Aug/20 ] |
|
Author: {'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}Message: (cherry picked from commit 59b1b711a622b6b1b77accbe459b064e52d45375) |
| Comment by Billy Donahue [ 07/May/20 ] |
|
Testing it out it little https://mongodbcr.appspot.com/602000022/ |
| Comment by Githook User [ 07/May/20 ] |
|
Author: {'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}Message: |
| Comment by Billy Donahue [ 15/Apr/20 ] |