Lazy-init variables are not always safe

Have you ever used following to lazy-initialize your variable?

codeshot.png
If you have then don’t.

Just to remind or introduce, it looks OK but it isn’t – this is a pretty serious bug you can easily make.

And it’s called Double-Checked Locking.
Very good and easy-to-understand explanation is here

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Anti-Spam Protection by WP-SpamFree