Greetings<div><br></div><div>Why is it necessary to use synchronized functions when passing shared variables? I get error even when I am not modifying the shared variable in the function.</div><div>Kindly look at the following code. I get a compile error unless I declare the functions parent and root synchronized.</div>

<div><br></div><div>The compile error says:</div><div>test.d(13): Error: function test.HierObject.root () const is not callable using argument types () shared const</div><div><br></div><div>Thanks and Regards</div><div>- Puneet</div>

<div><br></div><div>// Reduced Code</div><div><div><div>import std.exception;</div><div><br></div><div>// synchronized // Compiles without error when uncommented</div><div>class HierObject {</div><div>  private shared HierObject _root;</div>

<div>  private shared HierObject _parent;</div><div><br></div><div>  shared(const(HierObject)) root() const {</div><div>    if(_root) return _root;</div><div>    else {</div><div>      enforce(_parent,</div><div><span class="Apple-tab-span" style="white-space:pre"> </span>      "HierObject Instance does not have a parent!");</div>

<div>      return this.parent().root();</div><div>    }</div><div>  }</div><div><br></div><div>  shared(const(HierObject)) parent() const {</div><div>    enforce(_parent);</div><div>    return _parent;</div><div>  }</div>

<div>}</div></div></div><div><br></div>