简体   繁体   中英

Concurrent object destruction

I have misunderstandingn on sec. 3.6.3/1 N3797. When I considered initialization rule I come across with copy-initialization concept.

If the completion of the constructor or dynamic initialization of an object with static storage duration is sequenced before that of another, the completion of the destructor of the second is sequenced before the initiation of the destructor of the first. [ Note: This definition permits concurrent destruction. — end note ]

Is it possible that completion destructors of the second and of the first are in different threads?

Note: I edited and corrected the statement about unsequenced initialization (thanks to @dyp). If your program doesn't start any threads, then all initializations happen in some (possibly indeterminate) sequence.


There are no constraints beyond the constraints described in the Standard 1 on which threads perform initialization and destruction of objects with static storage duration. In particular, the initialization of objects in different translation units are indeterminately sequenced with respect to one another (cf. [basic.start.init]/2), and unsequenced if the program starts threads.

It is therefore possible for initializations to occur concurrently in multiple threads if the first function call within a TU occurs within another thread other than the main thread. What the standard says is that those objects whose initialization is sequenced (eg those in the same TU) are also destroyed in a deterministic, compatible order.

______________
1) "beyond what is said, nothing is said" — a bit it of a tautology, but worth calling out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM