Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

Is it safe for threads to share automatic storage duration (stack) objects via pointers or references?

0
Posted

Is it safe for threads to share automatic storage duration (stack) objects via pointers or references?

0

Only if you can guarantee that the lifetime of the stack object will not end while other threads might still access the object. Thus the safest practice is to avoid sharing stack objects, particularly in designs where threads are created and destroyed dynamically. Restrict sharing of stack objects to simple designs with very clear and unchanging function and thread lifetimes. (Suggested by Darryl Green).

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123