Do you need locking with only reading

I wanted to know that is it safe to assume that if multiple threads are accessing a single static container (boost::unordered_map) there is no need for locking the access to the container if multiple threads are only reading data from it. and no writing is done

Answers


When multiple threads are only reading and performing no write operation, you do not need to synchronize access.

Paragraph 1.10 of the C++11 Standard defines conflicting operations with respect to data races as:

Two expression evaluations conflict if one of them modifies a memory location (1.7) and the other one accesses or modifies the same memory location.

And then of course, per 1.10/21:

The execution of a program contains a data race if it contains two conflicting actions in different threads, at least one of which is not atomic, and neither happens before the other. [...]


Need Your Help

.net mvc 3 create and edit

c# asp.net-mvc asp.net-mvc-3 entity-framework

I've been struggling with creating and editing a model that contains another model as part of its model.

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.