Synchronisation of Static Objects

I have the following code C++ pseudo code

class A
 B s_staticvar;

 static void doSomething()

A number of threads can call doSomething(). All the threads only read s_staticvar & non modify them. My question is do we have to lock the static var before reading it ?

Can non atomic reads of the object B can cause synchronisation problems ?


You can safely read data from multiple threads. No locking is needed. These thread will not even notice each other. Only you need to ensure that you fully prepare your variable before other threads kick in.

In a multicore/multiprocessor environment it may happen that multiple copies of your data will be present in caches of different processors. This is not a problem as long as they are all the same.

Need Your Help

How to display images from external RSS feeds in WordPress?

wordpress rss thumbnails

Is there any way to show an image from RSS feeds in my WordPress page? Currently the default WordPress RSS feeds will only show the text of feeds from other sites. How can I make my site show a thu...

MySQL WHERE IN () + AND , PDO returns only one row

php mysql pdo fetch where-in

following query returns all wanted results if entered in phpmyadmin:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.