Greetings<div><br></div><div>I lately came across usefulness of "shared" qualifier in section 13.12.1. After reading the section, I guess I need to use shared qualifier more frequently than to just make sure that global variables are not treated thread-local. I think I need to make all class objects that would be accessed by multiple threads shared as well. Adding shared qualifier to these variables would make sure that the compiler adds memory barriers wherever applicable and that the compiler maintains sequential consistency for these objects. Am I right?</div>
<div><br></div><div>I tried to follow this on the application I am developing. Note that I am using threads from std.thread library (not MPI from std.concurrency). I started by adding shared qualifier on the variable declarations that I know would be accessed by multiple threads. To my surprise the compiler forces me to declare all the functions that take shared variables as parameters as synchronized. Since this applies to shared "this" objects as well, I am being forced to declare practically every method/function in my code as synchronous. While I understand that the compiler is trying to enforce such type checking to ensure mutex locking on shared objects, it is turning out to be pretty much impractical to use in my case. I would have preferred using synchronized code blocks for my critical sections instead of making all my functions synchronized.</div>
<div><br></div><div>Another issue is that the std container library does not seem to work with shared objects. So I have to do a lot of explicit casting while using this library with the objects that I have qualified as shared.</div>
<div><br></div><div>Kindly let me know if I am missing something. I tried google code search and could not find anybody using much of shared qualifier. While I know the number of shared objects has to be minimized by design, the nature of my application is such that I am forced to use std.thread library and am constrained to have lots of shared objects.</div>
<div><br></div><div>I am kind of stuck right now. Will appreciate any inputs.</div><div><br></div><div>Regards</div><div>- Puneet</div>